Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:
JavaWorld Daily Brew

gui questuin


Hi ,
I have wrote this program which should get a path address as an input and open the file. Where and how should I insert an ActionListener to execute my program!!!

JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Simplified English ");
frame.setLayout(new GridLayout(3, 2));
frame.add(new JLabel("please give your path"));
frame.add(new JTextField());
frame.add(new JButton("do it"));
int frameWidth = 200;
int frameHeight = 200;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setBounds((int) screenSize.getWidth() - frameWidth, 0, frameWidth, frameHeight);
frame.setVisible(true);

Your rating: None Average: 1 (1 vote)

import

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class SimpleSwing extends JFrame{
JFrame frame = null;
public SimpleSwing() {
JFrame.setDefaultLookAndFeelDecorated(true);
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Simplified English ");
frame.setLayout(new GridLayout(3, 2));
frame.add(new JLabel("please give your path"));
frame.add(new JTextField());
JButton doIt = new JButton("do it");
frame.add(doIt);

doIt.addActionListener(new ActionListener (){
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(frame, "Button Pressed");
}
});
int frameWidth = 200;
int frameHeight = 200;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setBounds((int) screenSize.getWidth() - frameWidth, 0, frameWidth, frameHeight);
frame.setVisible(true);
}

public static void main(String[] args) {
SimpleSwing start = new SimpleSwing();
}

}

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <p> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br /> <br> <strike>
  • Lines and paragraphs break automatically.
  • Use <!--pagebreak--> to create page breaks.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
Just checking to see if you're an actual person rather than a spammer. Sorry for the inconvenience.