Java?Swing實現(xiàn)記事本頁面
更新時間:2022年02月25日 10:50:49 作者:大菜彩
這篇文章主要為大家詳細介紹了Java?Swing實現(xiàn)記事本頁面,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Java Swing實現(xiàn)記事本頁面,供大家參考,具體內(nèi)容如下
代碼如下:
import java.awt.*;
import javax.swing.*;
public class Demo10 extends JFrame {
?? ?public Demo10() {
?? ??? ?super("記事本");
?? ??? ?//第一部分
?? ??? ?JMenuBar jme=new JMenuBar();
?? ??? ?
?? ??? ?JMenu jmenu1=new JMenu("文件(F)");
?? ??? ?JMenu jmenu2=new JMenu("編輯(E)");
?? ??? ?JMenu jmenu3=new JMenu("格式(O)");
?? ??? ?JMenu jmenu4=new JMenu("查看(V)");
?? ??? ?JMenu jmenu5=new JMenu("幫助(H)");
?? ??? ?
?? ??? ?JMenuItem ji1=new JMenuItem("新建");
?? ??? ?JMenuItem ji2=new JMenuItem("打開");
?? ??? ?JMenuItem ji3=new JMenuItem("保存(S) ?ctrl+s");
?? ??? ?JMenuItem ji4=new JMenuItem("另存為");
?? ??? ?JMenuItem ji5=new JMenuItem("頁面設(shè)置");
?? ??? ?JMenuItem ji6=new JMenuItem("打印");
?? ??? ?JMenuItem ji7=new JMenuItem("退出");
?? ??? ?
?? ??? ?
?? ??? ?jmenu1.add(ji1);
?? ??? ?jmenu1.add(ji2);
?? ??? ?jmenu1.add(ji3);
?? ??? ?jmenu1.add(ji4);
?? ??? ?jmenu1.add(ji5);
?? ??? ?jmenu1.add(ji6);
?? ??? ?jmenu1.add(ji7);
?? ??? ??? ?
?? ??? ?
?? ??? ?jme.add(jmenu1);
?? ??? ?jme.add(jmenu2);
?? ??? ?jme.add(jmenu3);
?? ??? ?jme.add(jmenu4);
?? ??? ?jme.add(jmenu5);
?? ??? ?
?? ??? ?//第二部分
?? ??? ?JButton jb1=new JButton();
?? ??? ?JButton jb2=new JButton();
?? ??? ?JButton jb3=new JButton();
?? ??? ?JButton jb4=new JButton();
?? ??? ?JButton jb5=new JButton();
?? ??? ?JButton jb6=new JButton();
?? ??? ?JButton jb7=new JButton();
?? ??? ?
?? ??? ?Icon icon1=new ImageIcon(this.getClass().getResource("/com/res/NEW.jpg"));
?? ??? ?Icon icon2=new ImageIcon(this.getClass().getResource("/com/res/COPY.jpg"));
?? ??? ?Icon icon3=new ImageIcon(this.getClass().getResource("/com/res/CUT.jpg"));
?? ??? ?Icon icon4=new ImageIcon(this.getClass().getResource("/com/res/note.jpg"));
?? ??? ?Icon icon5=new ImageIcon(this.getClass().getResource("/com/res/OPEN.jpg"));
?? ??? ?Icon icon6=new ImageIcon(this.getClass().getResource("/com/res/PASTE.jpg"));
?? ??? ?Icon icon7=new ImageIcon(this.getClass().getResource("/com/res/SAVE.jpg"));
?? ??? ?
?? ??? ?jb1.setIcon(icon1);
?? ??? ?jb2.setIcon(icon2);
?? ??? ?jb3.setIcon(icon3);
?? ??? ?jb4.setIcon(icon4);
?? ??? ?jb5.setIcon(icon5);
?? ??? ?jb6.setIcon(icon6);
?? ??? ?jb7.setIcon(icon7);
?? ??? ?//第三部分
?? ??? ?JTextArea jte=new JTextArea(10,42);
?? ??? ?
?? ??? ?JScrollPane jsc=new JScrollPane(jte);
?? ??? ?
?? ??? ?JPanel jp1=new JPanel();
?? ??? ?JPanel jp2=new JPanel();
?? ??? ?JPanel jp3=new JPanel();
?? ??? ?
?? ??? ?jp1.setLayout(new FlowLayout(0));
?? ??? ?jp1.add(jme);
?? ??? ?
?? ??? ?jp2.add(jb1);
?? ??? ?jp2.add(jb2);
?? ??? ?jp2.add(jb3);
?? ??? ?jp2.add(jb4);
?? ??? ?jp2.add(jb5);
?? ??? ?jp2.add(jb6);
?? ??? ?jp2.add(jb7);
?? ??? ?jp3.add(jsc);
?? ??? ?
?? ??? ?jp2.setLayout(new FlowLayout(0));
?? ??? ?jp3.setLayout(new FlowLayout(0));
?? ??? ?this.add(jp1,BorderLayout.NORTH);
?? ??? ?this.add(jp2,BorderLayout.CENTER);
?? ??? ?this.add(jp3,BorderLayout.SOUTH);
?? ??? ?this.setSize(500, 320);
?? ??? ?this.setVisible(true);
?? ??? ?this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
?? ??? ?this.setLocation(450, 120);
?? ?}
?? ?public static void main(String[] args) {
?? ??? ?new Demo10();
?? ?}
}運行結(jié)果:

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
關(guān)于使用MyBatis簡化JDBC開發(fā)和解決SQL語句警告的問題
這篇文章主要介紹了關(guān)于使用MyBatis簡化JDBC開發(fā)和解決SQL語句警告的問題,如果idea和數(shù)據(jù)庫沒有建立鏈接,idea不識別表的信息,就會出現(xiàn)SQL語句的警告,需要的朋友可以參考下2023-05-05
logback-spring.xml的內(nèi)容格式詳解
這篇文章主要介紹了logback-spring.xml的內(nèi)容格式詳解,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的的朋友參考下吧2023-11-11
emoji表情與unicode編碼互轉(zhuǎn)的實現(xiàn)(JS,JAVA,C#)
這篇文章主要介紹了emoji表情與unicode編碼互轉(zhuǎn)的實現(xiàn)(JS,JAVA,C#),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-01-01

