Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package components;
- import java.awt.*;
- import java.awt.event.*;
- import java.util.ArrayList;
- import javax.swing.*;
- public class JMenuExercise extends JFrame implements ActionListener {
- JFrame frame = new JFrame();
- JMenuBar menuBar = new JMenuBar();
- javax.swing.JMenu menu = new javax.swing.JMenu("Menu");
- JMenuItem addStudent = new JMenuItem("Add Student");
- JMenuItem addClub = new JMenuItem("Add Club");
- JMenuItem printInfo = new JMenuItem("Print Info");
- JPanel addStudentFrame = new JPanel();
- JPanel addClubFrame = new JPanel();
- JPanel printInfoFrame = new JPanel();
- JTextField textArea = new JTextField(" ");
- JButton submitStudent = new JButton("Submit");
- JButton submitClub = new JButton("Submit");
- ArrayList Students = new ArrayList();
- ArrayList Clubs = new ArrayList();
- public JMenuExercise() {
- menuBar.add(menu);
- menu.setLayout(new GridLayout(2,2,2,2));
- menu.add(addStudent);
- menu.add(addClub);
- menu.add(printInfo);
- addStudentFrame.setLayout(new GridLayout(2, 2, 20, 20));
- addStudentFrame.add(textArea);
- addStudentFrame.add(submitStudent);
- addClubFrame.setLayout(new GridLayout(2, 3, 20, 20));
- addClubFrame.add(textArea);
- addClubFrame.add(submitClub);
- printInfo.add(textArea);
- frame.setJMenuBar(menuBar);
- getContentPane().add(menuBar, BorderLayout.NORTH);
- getContentPane().add(addStudentFrame,BorderLayout.NORTH);
- this.setSize(400, 400);
- submitStudent.addActionListener(this);
- submitClub.addActionListener(this);
- addStudent.addActionListener(this);
- addClub.addActionListener(this);
- printInfo.addActionListener(this);
- }
- public static void main(String[] args) {
- JMenuExercise mainFrame = new JMenuExercise();
- mainFrame.setVisible(true);
- }
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == submitStudent) {
- System.out.println("Pressed1");
- }
- if (e.getSource() == submitClub) {
- System.out.println("Pressed2");
- }
- if (e.getSource() == addStudent) {
- System.out.println("Pressed3");
- }
- if (e.getSource() == addClub) {
- System.out.println("Pressed4");
- }
- if (e.getSource() == printInfo) {
- System.out.println("Pressed5");
- }
- }
- }
Add Comment
Please, Sign In to add comment