imageviewer.java

来自「现在在国外大学里最流行的java学习软件,同时还有大量的example,在名为p」· Java 代码 · 共 79 行

JAVA
79
字号
import java.awt.*;import java.awt.event.*;import javax.swing.*;/** * ImageViewer is the main class of the image viewer application. It builds  * and displays the application GUI. *  * To start the application, create an object of this class. *  * @author Michael Kolling and David J Barnes  * @version 0.2 */public class ImageViewer    implements ActionListener{    private JFrame frame;        /**     * Create an ImageViewer show it on screen.     */    public ImageViewer()    {        makeFrame();    }    /**     * Receive notification of an action.     * @param event Details of the action.     */    public void actionPerformed(ActionEvent event)     {         System.out.println("Item: " + event.getActionCommand());    }        // ---- swing stuff to build the frame and all its components ----        /**     * Create the Swing frame and its content.     */    private void makeFrame()    {        frame = new JFrame("ImageViewer");        makeMenuBar(frame);                Container contentPane = frame.getContentPane();                JLabel label = new JLabel("I am a label. I can display some text.");        contentPane.add(label);        // building is done - arrange the components and show                frame.pack();        frame.setVisible(true);    }        /**     * Create the main frame's menu bar.     * @param frame   The frame that the menu bar should be added to.     */    private void makeMenuBar(JFrame frame)    {        JMenuBar menubar = new JMenuBar();        frame.setJMenuBar(menubar);                // create the File menu        JMenu fileMenu = new JMenu("File");        menubar.add(fileMenu);                JMenuItem openItem = new JMenuItem("Open");        openItem.addActionListener(this);        fileMenu.add(openItem);        JMenuItem quitItem = new JMenuItem("Quit");        quitItem.addActionListener(this);        fileMenu.add(quitItem);    }}

⌨️ 快捷键说明

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