关闭

JFrame基础

150人阅读 评论(0) 收藏 举报
分类:

这里写图片描述
SimpleFrame

package proteena.LJK.about.JFrame;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class SimpleFrame extends JFrame implements ActionListener {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screenSize = toolkit.getScreenSize();
    int screenHeight = screenSize.height;
    int screenWidth = screenSize.width;

    private JButton button = new JButton("Yes");

    public SimpleFrame() {
        setSize(screenWidth/2, screenHeight/2);
        setMenu();
        JPanel jp=new JPanel();
        jp.setBackground(Color.pink);
        jp.add(button);
        add(jp);
//      this.getContentPane().setVisible(false);
//      setBackground(Color.yellow);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }

    public void setMenu() {
        MenuBar menuBar = new MenuBar();
        Menu file = new Menu("File");
        file.add("New");
        MenuItem save = new MenuItem("Save");
        file.add(save);
        menuBar.add(file);
        this.setMenuBar(menuBar);
    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub

    }
}

SimpleFrameTest

package proteena.LJK.about.JFrame;

import java.awt.EventQueue;

public class SimpleFrameTest {

    public static void main(String[] args) {

        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                SimpleFrame frame = new SimpleFrame();
                frame.setTitle("NotePad");
            }
        });
    }

}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:5095次
    • 积分:173
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:10篇
    • 译文:0篇
    • 评论:1条
    文章分类