Transcript
Page 1: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日

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

TA : Seunghan Chang

([email protected])

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

23年 4月 19日 2/16

Example GUI in Java(1)

Page 3: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 3/16

Example GUI in Java(2) 1. JFame

2. JPanel

5. JTextField

4. JLabel

6. JButton

3. JMenu

Please click me to see how this GUI works

Page 4: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 4/16

Programming Environments

Page 5: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 5/16

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"); }

Page 6: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 6/16

Example GUI in Java 1. JFame

2. JPanel

5. JTextField

4. JLabel

6. JButton

3. JMenu

Page 7: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 7/16

JPanel : Conference

JPanel conferencePanel = new JPanel();

conferencePanel.setLayout(new GridLayout(2,4));

conferencePanel.setBorder(BorderFactory.createLineBorder(Color.blue, 2));

conferencePanel.setBorder(BorderFactory.createTitledBorder("Conference"));

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);

JPanel publicationPanel_2 = new JPanel();

publicationPanel_2.setLayout(new FlowLayout(FlowLayout.LEFT));

publicationPanel.add(publicationPanel_2);

Layout Manager

Page 8: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 8/16

Example GUI in Java 1. JFame

2. JPanel

5. JTextField

4. JLabel

6. JButton

3. JMenu

Page 9: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 9/16

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);

Page 10: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 10/16

Example GUI in Java 1. JFame

2. JPanel

5. JTextField

4. JLabel

6. JButton

3. JMenu

Page 11: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 11/16

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);

Page 12: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 12/16

Example GUI in Java 1. JFame

2. JPanel

5. JTextField

4. JLabel

6. JButton

3. JMenu

Page 13: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 13/16

JTextField

private static JTextField sampleJTextField_12 = null;

sampleJTextField_12 = new JTextField(70);

publicationPanel_2.add(sampleJTextField_12);

Page 14: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 14/16

Example GUI in Java 1. JFame

2. JPanel

5. JTextField

4. JLabel

6. JButton

3. JMenu

Page 15: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 15/16

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); } } );

Page 16: Tutorial for Project (Part 2) (GUI in Java)

23年 4月 19日 16/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


Top Related