1 / 16

Tutorial for Project (Part 2) (GUI in Java)

Tutorial for Project (Part 2) (GUI in Java). TA : Seunghan Chang ( aq9320@wayne.edu ). Example GUI in Java(1). 4. JLabel. 1. JFame. 2. JPanel. 3. JMenu. 5. JTextField. 6. JButton. Example GUI in Java(2). Please click me to see how this GUI works. Programming Environments. JFrame.

Download Presentation

Tutorial for Project (Part 2) (GUI in Java)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial for Project (Part 2)(GUI in Java) TA : Seunghan Chang (aq9320@wayne.edu)

  2. Example GUI in Java(1)

  3. 4. JLabel 1. JFame 2. JPanel 3. JMenu 5. JTextField 6. JButton Example GUI in Java(2) Please click me to see how this GUI works

  4. Programming Environments

  5. JFrame sampleFrame = new MainFrame(); sampleFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0); }}); . . . sampleFrame.show(); class MainFrame extends JFrame { public MainFrame() { Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int h = screenSize.height; int w = screenSize.width; setSize(w-100,h-100); setLocation(10, 10); setTitle("Sample Frame"); }

  6. Example GUI in Java 4. JLabel 1. JFame 2. JPanel 3. JMenu 5. JTextField 6. JButton

  7. JPanel : Conference JPanel conferencePanel = new JPanel(); conferencePanel.setLayout(new GridLayout(2,4)); conferencePanel.setBorder(BorderFactory.createLineBorder(Color.blue, 2)); conferencePanel.setBorder(BorderFactory.createTitledBorder("Conference")); JPanel publicationPanel_2 = new JPanel(); publicationPanel_2.setLayout(new FlowLayout(FlowLayout.LEFT)); publicationPanel.add(publicationPanel_2); Container contentPane = sampleFrame.getContentPane();contentPane.setLayout(new GridLayout(6,1)); contentPane.add(titlePanel); contentPane.add(conferencePanel); contentPane.add(proceedingsPanel); contentPane.add(publicationPanel); contentPane.add(emptyPanel); contentPane.add(buttonPanel); Layout Manager

  8. Example GUI in Java 4. JLabel 1. JFame 2. JPanel 3. JMenu 5. JTextField 6. JButton

  9. JMenu JMenuBar menuBar = new JMenuBar(); sampleFrame.setJMenuBar(menuBar); JMenu samplemenu1 = new JMenu("Menu1"); samplemenu1.setMnemonic('1'); . . . menuBar.add(samplemenu1); . . . Action menu1Action = new AbstractAction("Menu1") {public void actionPerformed(ActionEvent e) {JOptionPane.showMessageDialog(sampleFrame, "You selected Menu1", "Menu1", JOptionPane.INFORMATION_MESSAGE);}}; menu1Action.putValue(Action.MNEMONIC_KEY, new Integer('1')); samplemenu1.add(menu1Action);

  10. Example GUI in Java 4. JLabel 1. JFame 2. JPanel 3. JMenu 5. JTextField 6. JButton

  11. JLabel JLabel titleLabel = new JLabel(); titleLabel.setHorizontalTextPosition(JLabel. CENTER); titleLabel.setText("Conference Publication Insertion"); Font f = new Font("Arial", Font.BOLD, 30); titleLabel.setForeground(Color.blue); titleLabel.setFont(f); titlePanel.add(titleLabel);

  12. Example GUI in Java 4. JLabel 1. JFame 2. JPanel 3. JMenu 5. JTextField 6. JButton

  13. JTextField private static JTextField sampleJTextField_12 = null; sampleJTextField_12 = new JTextField(70); publicationPanel_2.add(sampleJTextField_12);

  14. Example GUI in Java 4. JLabel 1. JFame 2. JPanel 3. JMenu 5. JTextField 6. JButton

  15. JButton private static JButton sampleJButton1 = null; JButton sampleJButton1 = new JButton("Insert"); buttonPanel.add(sampleJButton1); sampleJButton1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {JOptionPane.showMessageDialog(sampleFrame, "You selected Insert Button", "Insert", JOptionPane.INFORMATION_MESSAGE);}});

  16. For More Useful Information http://java.sun.com/docs/books/tutorial/ui/features/components.html http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JComponent.html Thanks and Good Luck

More Related