Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.samkough.main;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- @SuppressWarnings("serial")
- public class Sam extends JFrame
- {
- private static final int WIDTH = 500;
- private static final int HEIGHT = 500;
- JButton b1;
- JLabel l1;
- JTextField tf1;
- JRadioButton rb1;
- JCheckBox cb1;
- JMenuItem mi1;
- public static void main(String args[])
- {
- Sam frame = new Sam();
- frame.setVisible(true);
- frame.setTitle("GUI");
- frame.setSize(WIDTH, HEIGHT);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- }
- public Sam()
- {
- setLayout(new FlowLayout());
- b1 = new JButton("Press me!");
- l1 = new JLabel("");
- tf1 = new JTextField("", 7);
- rb1 = new JRadioButton("");
- cb1 = new JCheckBox("");
- mi1 = new JMenuItem("");
- add(b1);
- add(l1);
- add(tf1);
- add(rb1);
- add(cb1);
- add(mi1);
- Action e = new Action();
- b1.addActionListener(e);
- }
- public class Action implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- b1.setText("Button");
- l1.setText("Label");
- tf1.setText("Text Field");
- rb1.setText("Radio Button");
- cb1.setText("Check Box");
- mi1.setText("Menu Item");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment