We Can access a Form's Control such as TextBox,ComboBox,datagridview etc. From another Form by passing current Form Object into another Form via an Overloaded constructor.
Ex:
In form 1
Form2 f1 = new Form2(this);
f1.ShowDialog();
then In Form2
Form1 form1;
public Form2(Form1 f)
{
InitializeComponent();
this.form1 = f;
}
we can easily access form1's TextBox like
form1.textBox1.Text="Hi,This is Form2";
Note : Modifiers property of Form1's TextBox1 should be declared as Public.
Thank you
It's all about my thoughts about the people, happenings, films, sports, books, problems, programmings I came across in my life.
Thursday, April 30, 2009
Passing Information between Windows Forms
We can Pass Information from One Form to another Form
via an Overloaded Constructor.
In form1,we have to pass value in constructor on Object Creation.
Ex:
Form2 f2 = new Form2(UserName);
f2.ShowDialog();
Then in Form2,we have to assign Passed value in a Local variable or control.
Here UserName refers a String Variable which contains User Name entered in form1.
Ex:
String uname;
public Form2(String username)
{
InitializeComponent();
textBox1.Text =username ;
uname=username;
}
Now textBox1 & variable uname contains value Entered in Form1
Thank you.
via an Overloaded Constructor.
In form1,we have to pass value in constructor on Object Creation.
Ex:
Form2 f2 = new Form2(UserName);
f2.ShowDialog();
Then in Form2,we have to assign Passed value in a Local variable or control.
Here UserName refers a String Variable which contains User Name entered in form1.
Ex:
String uname;
public Form2(String username)
{
InitializeComponent();
textBox1.Text =username ;
uname=username;
}
Now textBox1 & variable uname contains value Entered in Form1
Thank you.
Monday, April 20, 2009
My First Website
I just built a website for JK Constructions which is the first website developed by me ever.In College Days, I have created some website templates for a German company through my brother. On those days, I just copied some samples from websites and try to build templates using HTML.
But Now i built a website using ASP.NET,C#.NET & XML.In My UG project, i have used XML for storing data.In the beginning, i have some doubts on XML ability to use it as database.But at the end, I m very much satisfied with XML.
All works such as designing,coding,Registering domain,hosting website are done by me without any help.
It is a very good experience for me.I m the only and only person from computer filed in that company.All are from construction field.Its very tough to understand their requirements.and the thing which is too tough is to explain the limitations of a website.I have learnt a lot of good lessons on those days.
take a look on my fist website
JK constructions
But Now i built a website using ASP.NET,C#.NET & XML.In My UG project, i have used XML for storing data.In the beginning, i have some doubts on XML ability to use it as database.But at the end, I m very much satisfied with XML.
All works such as designing,coding,Registering domain,hosting website are done by me without any help.
It is a very good experience for me.I m the only and only person from computer filed in that company.All are from construction field.Its very tough to understand their requirements.and the thing which is too tough is to explain the limitations of a website.I have learnt a lot of good lessons on those days.
take a look on my fist website
JK constructions
Wednesday, April 15, 2009
JAVA Simple Printing
PrintJob class is used for printing in JAVA.
you have to format the things which you need to take printout.
you can draw rectangle,line any graphics object and also string.
you can set Font & Color for that
EX:
PrintJob job = getToolkit().getPrintJob(fr,"PRINT",null);
Graphics g=job.getGraphics();
g.drawRect(50,30,525,775);
g.setFont(new Font("TimesRoman",Font.BOLD,16));
g.drawString("Welcome to JAVA",220,50);
g.drawLine(50,80,50,500);
g.dispose();
job.end();
Here
fr refers frame object.
g.drawRect(xposition,yposition,width,height);
g.drawString("String to print",Xposition,yposition);
g.drawLine(StartX,StartY,EndX,Endy);
output:
This will draw a rectangle... It will be the complete border for A4 sheet.
after that draw "Welcome to JAVA in TimesRoman font with bold.
And draw Line
then it End the print job
Thank you
you have to format the things which you need to take printout.
you can draw rectangle,line any graphics object and also string.
you can set Font & Color for that
EX:
PrintJob job = getToolkit().getPrintJob(fr,"PRINT",null);
Graphics g=job.getGraphics();
g.drawRect(50,30,525,775);
g.setFont(new Font("TimesRoman",Font.BOLD,16));
g.drawString("Welcome to JAVA",220,50);
g.drawLine(50,80,50,500);
g.dispose();
job.end();
Here
fr refers frame object.
g.drawRect(xposition,yposition,width,height);
g.drawString("String to print",Xposition,yposition);
g.drawLine(StartX,StartY,EndX,Endy);
output:
This will draw a rectangle... It will be the complete border for A4 sheet.
after that draw "Welcome to JAVA in TimesRoman font with bold.
And draw Line
then it End the print job
Thank you
Tuesday, April 14, 2009
JAVA Message,Input and Confirm Dialog Box
In java JOptionPane class is used to show Message and also used to get Input from user
Message Box
There are different type of Message Box are available Normal,Error and Warning message box
JOptionPane.showMessageDialog("your Message","Title");
Error Message
JOptionPane.showMessageDialog("your Message","Title",JOptionPane.ERROR_MESSAGE);
Warning Message
JOptionPane.showMessageDialog("your Message","Title",JOptionPane.WARNING_MESSAGE);
Input Box
In order to get a value from user. we can use showInputDialog() Method.
we have to Pass current frame object to that msg
String value=JOptionPane.showInputDialog(fr,"Plz enter Value ");
Input Box with Default value
String value=JOptionPane.showInputDialog(fr,"Plz enter Value ","Default value");
Confirm Dialog
This can be used with following options
Yes No
Retry Ignore Cancel
OK Cancel
Ex for YES NO confirm Dialog
int result=JOptionPane.showConfirmDialog(fr,"Do you Want to Save it","Save",JOptionPane.YES_NO_OPTION);
Note :
here,
result contains 0 or 1..
o refers YES and 1 refers NO
fr -> frame object
"Do you Want to Save it", -> Question
"Save", ->Header
JOptionPane.YES_NO_OPTION -> Option
Thank you
Message Box
There are different type of Message Box are available Normal,Error and Warning message box
JOptionPane.showMessageDialog("your Message","Title");
Error Message
JOptionPane.showMessageDialog("your Message","Title",JOptionPane.ERROR_MESSAGE);
Warning Message
JOptionPane.showMessageDialog("your Message","Title",JOptionPane.WARNING_MESSAGE);
Input Box
In order to get a value from user. we can use showInputDialog() Method.
we have to Pass current frame object to that msg
String value=JOptionPane.showInputDialog(fr,"Plz enter Value ");
Input Box with Default value
String value=JOptionPane.showInputDialog(fr,"Plz enter Value ","Default value");
Confirm Dialog
This can be used with following options
Yes No
Retry Ignore Cancel
OK Cancel
Ex for YES NO confirm Dialog
int result=JOptionPane.showConfirmDialog(fr,"Do you Want to Save it","Save",JOptionPane.YES_NO_OPTION);
Note :
here,
result contains 0 or 1..
o refers YES and 1 refers NO
fr -> frame object
"Do you Want to Save it", -> Question
"Save", ->Header
JOptionPane.YES_NO_OPTION -> Option
Thank you
JAVA Table with Combobox control
In java swing we can add Controls in table.
Here we are going to add Combobox in a table control.
Before going to create a table instance, we have to create table headers and data with empty strings like below
final String[] colheads={"S.No","Item ID","Qty",Rate","Amount" };
final Object[][] data={
{1,"","","",""},
{2,"","","",""},
{3,"","","",""},
{4,"","","",""},
{5,"","","",""},
};
Now we create a table and add scroll panes to it...
JTable table=new JTable(data,colheads);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp=new JScrollPane(table,v,h);
Note: add this table into panel to show...
Then to add combo box in the run time, we add code in focus gained event of table like below..
public void focusGained(FocusEvent e)
{
TableColumn tc=table.getColumnModel().getColumn(1);
JComboBox dw=new JComboBox();
dw.addItem("Select");
dw.addItem("IN1");
dw.addItem("IN2");
dw.addItem("IN3");
dw.addItem("IN4");
tc.setCellEditor(new DefaultCellEditor(dw));
}
Note: we have to add focus listener to table and after that add code for it..in the focus gained method we have to add above code..
In the output,It will show a table.. when you access table you can able select item values at column 2...
Thank you
Here we are going to add Combobox in a table control.
Before going to create a table instance, we have to create table headers and data with empty strings like below
final String[] colheads={"S.No","Item ID","Qty",Rate","Amount" };
final Object[][] data={
{1,"","","",""},
{2,"","","",""},
{3,"","","",""},
{4,"","","",""},
{5,"","","",""},
};
Now we create a table and add scroll panes to it...
JTable table=new JTable(data,colheads);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp=new JScrollPane(table,v,h);
Note: add this table into panel to show...
Then to add combo box in the run time, we add code in focus gained event of table like below..
public void focusGained(FocusEvent e)
{
TableColumn tc=table.getColumnModel().getColumn(1);
JComboBox dw=new JComboBox();
dw.addItem("Select");
dw.addItem("IN1");
dw.addItem("IN2");
dw.addItem("IN3");
dw.addItem("IN4");
tc.setCellEditor(new DefaultCellEditor(dw));
}
Note: we have to add focus listener to table and after that add code for it..in the focus gained method we have to add above code..
In the output,It will show a table.. when you access table you can able select item values at column 2...
Thank you
Subscribe to:
Posts (Atom)