⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toolbardemo.java

📁 Java与面向对象程序设计实验教学讲义.复数类的实现,复数类的复杂运算,身份证号码的分析,图形界面设计
💻 JAVA
字号:
import javax.swing.JToolBar;import javax.swing.JButton;import javax.swing.ImageIcon;import javax.swing.JFrame;import javax.swing.JTextArea;import javax.swing.JScrollPane;import javax.swing.JPanel;import java.awt.*;import java.awt.event.*;public class ToolBarDemo extends JFrame {    protected JTextArea textArea;    protected String newline = "\n";    public ToolBarDemo() {        //Do frame stuff.        super("ToolBarDemo");        addWindowListener(new WindowAdapter() {            public void windowClosing(WindowEvent e) {                System.exit(0);            }        });        //Create the toolbar.        JToolBar toolBar = new JToolBar();        addButtons(toolBar);        //Create the text area used for output.        textArea = new JTextArea(5, 30);        JScrollPane scrollPane = new JScrollPane(textArea);        //Lay out the content pane.        JPanel contentPane = new JPanel();        contentPane.setLayout(new BorderLayout());        contentPane.setPreferredSize(new Dimension(400, 100));        contentPane.add(toolBar, BorderLayout.NORTH);        contentPane.add(scrollPane, BorderLayout.CENTER);        setContentPane(contentPane);    }    protected void addButtons(JToolBar toolBar) {        JButton button = null;        //first button        button = new JButton(new ImageIcon("./build/classes/left.gif"));        button.setToolTipText("This is the left button");        button.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                displayResult("Action for first button");            }        });        toolBar.add(button);        //second button        button = new JButton(new ImageIcon("./build/classes/middle.gif"));        button.setToolTipText("This is the middle button");        button.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                displayResult("Action for second button");            }        });        toolBar.add(button);        //third button        button = new JButton(new ImageIcon("./build/classes/right.gif"));        button.setToolTipText("This is the right button");        button.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                displayResult("Action for third button");            }        });        toolBar.add(button);    }    protected void displayResult(String actionDescription) {        textArea.append(actionDescription + newline);    }    public static void main(String[] args) {        ToolBarDemo frame = new ToolBarDemo();        frame.pack();        frame.setVisible(true);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -