开发者社区> 问答> 正文

java Application怎样编写?

java Application怎样编写?

展开
收起
gxx1 2022-04-01 01:53:13 399 0
1 条回答
写回答
取消 提交回答

  • 新建类CloseFrame.java,代码如下:


    import java.awt.BorderLayout;

    import java.awt.FlowLayout;

    import java.awt.event.ActionEvent;

    import java.awt.event.ActionListener;

    import javax.swing.JButton;

    import javax.swing.JFrame;

    import javax.swing.JMenu;

    import javax.swing.JMenuBar;

    import javax.swing.JMenuItem;

    import javax.swing.JPanel;

    public class CloseFrame extends JFrame implements ActionListener {

    JMenuBar menu;

    JMenu file;

    JMenuItem closeMenu;

    public CloseFrame() {

    menu = new JMenuBar();

    file = new JMenu("文件");

    closeMenu = new JMenuItem("关闭");

    closeMenu.addActionListener(this);

    JButton closeButton = new JButton(" 关闭 ");

    closeButton.addActionListener(this);

    JPanel closePanel = new JPanel();

    closePanel.setLayout(new FlowLayout());

    closePanel.add(closeButton);

    this.add(closePanel, BorderLayout.CENTER);

    this.add(menu, BorderLayout.NORTH);

    menu.add(file);

    file.add(closeMenu);

    this.setBounds(200, 100, 200, 120);

    this.setVisible(true);

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }

    public void actionPerformed(ActionEvent e) { System.exit(0);

    }

    public static void main(String[] args) { new CloseFrame();

    }

    }

    通过上述代码就可以进行它的编写,我们可以根据其进行应用。

    2022-04-01 01:54:55
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载