JFrame基础

这里写图片描述
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");
            }
        });
    }

}
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/proteena_LJK/article/details/49909271
个人分类: JFrame
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

JFrame基础

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭