System.exit(0);
}
});
button1=new JButton(new ImageIcon("image/PreviousArrow.gif"));
button2=new JButton(new ImageIcon("image/go.GIF"));
button3=new JButton(new ImageIcon("image/NextArrow.gif"));
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
toolBar=new JToolBar();
toolBar.add(button1);
toolBar.add(button2);
toolBar.add(button3);
textArea=new JTextArea(6,30);
scrollPane=new JScrollPane(textArea);
panel=new JPanel();
setContentPane(panel);
panel.setLayout(new BorderLayout());
panel.setPreferredSize(new Dimension(300,150));
panel.add(toolBar,BorderLayout.NORTH);
panel.add(scrollPane,BorderLayout.CENTER);
pack();
show();
}
public void actionPerformed(ActionEvent e) {
String s="";
if (e.getSource()==button1)
s="左按钮被单击\n";
else if (e.getSource()==button2)
s="中按钮被单击\n";
else if (e.getSource()==button3)
s="右按钮被单击\n";
textArea.append(s);
}
}
(4)编译LX5_9.java。
(5)运行LX5_9.class,产生的窗口界面如图6.9 所示。