.


:




:

































 

 

 

 


Swing




: , , .. , ( , ), ( , ..).

, , . Swing .

ActionListener

, ( , ), , , . , , .

ActionListener, :

public void actionPerformed(ActionEvent event).

ActionListener . , .

JButton , , .

, ActionEvent, . , , Swing ActionListener, . ActionListener actionPerformed. , ActionListener .

public class TestActionListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

//,

}}

, , . addActionListener. . , :

JButton button = new JButton("Test button");

ActionListener actionListener = new TestActionListener();

button.addActionListener(actionListener);

. TestActionListener, addActionListener . . , - , addActionListener.

Swing

, . , (, , , ).

Swing JMenuBar. BoxLayout ( ), , : , . .

 

setJMenuBar(JMenuBar menuBar).

JMenu. JMenu(String title) : , .

, , , JMenuItem. JButton, - .

JMenuItem ( ) , / : JMenuItem(String text), JMenuItem(Icon icon), JMenuItem(String text, Icon icon). , setText(String text) setIcon(Icon icon) .

add(JMenuItem item) JMenu. , addSeparator() JMenu.

, . , . : .

, : , . , , ( , Internet Explorer).

SimpleWindow(){

super(" ");

setDefaultCloseOperation(EXIT_ON_CLOSE);

JMenuBar menuBar = new JMenuBar();

JMenu fileMenu = new JMenu("");

fileMenu.add(new JMenuItem(""));

fileMenu.add(new JMenuItem("", new ImageIcon("1.gif")));

fileMenu.add(new JMenuItem(""));

fileMenu.addSeparator();

fileMenu.add(new JMenuItem(""));

JMenu editMenu = new JMenu("");

editMenu.add(new JMenuItem(""));

JMenu pasteMenu = new JMenu("");

pasteMenu.add(new JMenuItem(" "));

pasteMenu.add(new JMenuItem(" "));

editMenu.add(pasteMenu);

menuBar.add(fileMenu);

menuBar.add(editMenu);

menuBar.add(Box.createHorizontalGlue());

menuBar.add(new JLabel(new ImageIcon("2.gif")));

setJMenuBar(menuBar);

setSize(250,150);

}

, , , . , . , ,

fileMenu.add(new JMenuItem(""));

:

JMenuItem exit = new JMenuItem("");

exit.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

System.exit(0);}});

fileMenu.add(exit);

System.exit(0) .





:


: 2016-11-02; !; : 756 |


:

:

, .
==> ...

1377 - | 1153 -


© 2015-2024 lektsii.org - -

: 0.012 .