JFrame模板

来源:互联网 发布:windows应用程序错误 编辑:程序博客网 时间:2024/04/28 03:54

写下JFrame模板,留作以后写JFrame的通用代码大笑

package JFrame;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.io.IOException;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.WindowConstants;import com.sun.java.swing.plaf.windows.resources.windows;public class Frame extends JFrame {public static void main(String[] args) {Frame fr=new Frame();fr.setVisible(true);//设置窗体可见fr.setTitle("Code Smell");fr.setSize(400, 500);//设置窗体大小fr.setLocationRelativeTo(null);//居中显示fr.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);//关闭窗口时,让程序也停止运行JMenuBar jm=new JMenuBar();//创建菜单条对象JMenu jm1;//菜单JMenuItem jmi11,jmi12;//菜单项jm1=new JMenu("file");//定义菜单//在每个菜单上都添加菜单项jm1.add(jmi11=new JMenuItem("loading"));jm1.add(jmi12=new JMenuItem("exit"));jm.add(jm1);//把菜单添加到菜单条fr.setJMenuBar(jm);//把菜单条添加到窗口上     //测试loading菜单的触发事件jmi11.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {try {System.out.println("这是点击loading菜单之后的具体逻辑");} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}}});}}


0 0
原创粉丝点击