Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package swing;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class SWING {
- private JFrame frame;
- private JPanel panel;
- private JLabel label;
- private JTextField textField;
- private JButton button;
- private JButton button1;
- public SWING(){
- label = new JLabel("Enter Your Name");
- textField = new JTextField(10);
- button = new JButton("OK");
- button1 = new JButton("Submit");
- panel = new JPanel();
- panel.add(label);
- panel.add(textField);
- panel.add(button);
- panel.add(button1);
- buttonPressed sPressed =new buttonPressed();
- button.addActionListener(sPressed);
- button1.addActionListener(sPressed);
- JFrame frame = new JFrame("App Title");
- frame.add(panel);
- frame.setSize(400, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocation(150, 150);
- frame.setVisible(true);
- }
- public class buttonPressed implements ActionListener{
- @Override
- public void actionPerformed(ActionEvent e) {
- String input = textField.getText().toString();
- JOptionPane.showMessageDialog(panel, "Hello "+input);
- System.out.println("Hello World "+e.getActionCommand());
- }
- }
- public static void main(String[] args) {
- SWING app = new SWING();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement