好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Java Swing实现记事本页面

本文实例为大家分享了Java Swing实现记事本页面,供大家参考,具体内容如下

代码如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

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( "页面设置" );

         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();

     }

}

运行结果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

原文链接:https://blog.csdn.net/qq_53786696/article/details/117325514

查看更多关于Java Swing实现记事本页面的详细内容...

  阅读:19次