• Post Reply Bookmark Topic Watch Topic
  • New Topic

simple program not working in swing

 
Vishal Methi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi frnds,
I m new in swing programming, frnds i wrote a sample progam which is shown below.. it shows me the frame but inside that i m not able to view the two jtextfileds and the button...
its two imp for me now.. could u plz help the and tell me where i m wrong...

plz reply me asap...
public class CopyFilesUI extends JFrame{
private JTextField sourceFile = new JTextField ("Source file name");
private JTextField destinationFile = new JTextField ("Destination file name");
private JButton button = new JButton ("Backup");

public CopyFilesUI ()
{
this.getContentPane().setLayout(null);
sourceFile.setBounds( 50 , 50 , 50 , 50);
sourceFile.setVisible(true);
destinationFile.setBounds(150 , 150 , 50 , 50);
sourceFile.setVisible(true);
button.setBounds(250 , 250 , 250 , 250);
sourceFile.setVisible(true);

this.setTitle("Copy files");
this.setVisible(true);
this.setBounds(0 , 0 , 700 , 700);
this.set
}


public static void main(String[] args) {
CopyFilesUI copyFiles = new CopyFilesUI ();
copyFiles.setEnabled(true);


}
}


thanx for ur co-opearation..
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not actually adding them to your frame. Try this:

this.getContentPane().add(sourceFile);
this.getContentPane().add(destinationFile);
this.getContentPane().add(button);
 
Vishal Methi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx a lot very much...
Now its working .. but now i have one problem...
can u plz tell me how to write the actionperformed event for button.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Tutorial has a section on ActionListeners.
 
Vishal Methi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx man...
Now its working properly...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!