码迷,mamicode.com
首页 > 其他好文 > 详细

JFrame部分功能

时间:2019-05-12 18:23:39      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:package   bsp   str   equals   static   import   完成   remove   text   

  //未完成
1
package test; 2 import javax.swing.*; 3 import java.awt.*; 4 import java.awt.event.ActionEvent; 5 import java.awt.event.ActionListener; 6 import java.awt.*; 7 class Enter{ 8 9 public void Enter() { 10 JFrame JF=new JFrame("注册账号"); 11 Container container=JF.getFocusCycleRootAncestor(); 12 JF.setSize(300, 300); 13 JPanel a1=new JPanel(); 14 JLabel b1=new JLabel("账号:"); 15 JTextField c1=new JTextField(3); 16 c1.getText(); 17 18 a1.add(b1); 19 a1.add(c1); 20 JPanel a2=new JPanel(); 21 JLabel b2=new JLabel("密码:"); 22 JTextField c2=new JTextField(3); 23 c2.getText(); 24 a2.add(b2); 25 a2.add(c2); 26 JPanel a3=new JPanel(); 27 JButton d1=new JButton("确定"); 28 JButton d2=new JButton("取消"); 29 //给按钮添加 30 d1.addActionListener(new ActionListener() { 31 32 public void actionPerformed(ActionEvent e) { 33 tesst m=new tesst(); 34 m.b(c1.getText(), c2.getText()); 35 JF.setVisible(false); 36 } 37 38 }); 39 a3.add(d1); 40 a3.add(d2); 41 JF.setLayout(new GridLayout(3,1)); 42 JF.add(a1); 43 JF.add(a2); 44 JF.add(a3); 45 JF.setVisible(true); 46 JF.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 47 } 48 49 50 } 51 class CreatJDialog{ 52 public void JDialog() { 53 JDialog jd=new JDialog(); 54 Container container=jd.getContentPane(); 55 container.setLayout(null); 56 jd.setTitle("开始游戏"); 57 jd.setSize(250, 150); 58 jd.setLayout(new GridLayout(3,1)); 59 JPanel cib_6=new JPanel(); 60 JPanel cib_7=new JPanel(); 61 JButton jb1=new JButton("开始"); 62 JButton jb2=new JButton("退出"); 63 jb1.setSize(10, 10); 64 String str_2[]= {"==请选择怪物==","王佳胜","苏炎"}; 65 JComboBox a=new JComboBox(str_2); 66 a.removeAllItems(); 67 jb1.addActionListener(new ActionListener(){ 68 public void actionPerformed(ActionEvent e) { 69 for(int i=0;i<3;i++) { 70 a.addItem(str_2[i]); 71 } 72 } 73 74 }); 75 cib_6.add(a); 76 cib_7.add(jb1); 77 cib_7.add(jb2); 78 jd.add(cib_6); 79 jd.add(cib_7); 80 jd.setVisible(true); 81 82 } 83 84 } 85 class tesst{ 86 public void b(String e1,String e2) { 87 System.out.println(e1); 88 System.out.println(e2); 89 JFrame jf2=new JFrame("请输入账号密码"); 90 Container container=jf2.getContentPane(); 91 jf2.setSize(300, 300); 92 JPanel JP1=new JPanel(); 93 JLabel JL1=new JLabel("账号:"); 94 JTextField c1=new JTextField(20); 95 96 JP1.setLayout(new FlowLayout()); 97 JP1.add(JL1); 98 JP1.add(c1); 99 JPanel JP2=new JPanel(); 100 JLabel JL2=new JLabel("密码:"); 101 JTextField c2=new JTextField(20); 102 JP2.add(JL2); 103 JP2.add(c2); 104 JPanel JP3=new JPanel(); 105 JButton d1=new JButton("确定"); 106 JButton d2=new JButton("取消"); 107 //为d1按钮添加事件 108 109 d1.addActionListener(new ActionListener() { 110 public void actionPerformed(ActionEvent e) { 111 if(e1.equals(c1.getText())&&e2.equals(c2.getText())) { 112 //检验是否传值成功 113 System.out.println(c1.getText()); 114 System.out.println(c2.getText()); 115 }else { 116 //检验是否传值成功 117 System.out.println("错误"); 118 System.out.println(c2.getText()); 119 } 120 121 jf2.setVisible(false); 122 123 JFrame aa=new JFrame("提示窗口"); 124 aa.setSize(200,100); 125 aa.setVisible(true); 126 127 aa.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 128 129 130 aa.setLayout(new GridLayout(2,1)); 131 JButton A=new JButton("登入成功"); 132 aa.add(A); 133 JButton B=new JButton("继续"); 134 aa.add(B); 135 B.addActionListener(new ActionListener() { 136 public void actionPerformed(ActionEvent e) { 137 aa.setVisible(false); 138 new CreatJFrame().a(); 139 140 } 141 142 }); 143 144 145 } 146 147 }); 148 149 JP3.add(d1); 150 JP3.add(d2); 151 jf2.setLayout(new GridLayout(3,1)); 152 jf2.add(JP1); 153 jf2.add(JP2); 154 jf2.add(JP3); 155 jf2.setVisible(true); 156 jf2.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 157 } 158 } 159 class CreatJFrame{ 160 public void a() { 161 JFrame jf=new JFrame("创建角色"); 162 Container container=jf.getContentPane(); 163 container.setLayout(null); 164 jf.setSize(250,150); 165 String str[]={"==请选择==","新手","老兵","真实"}; 166 JComboBox cib=new JComboBox(str); 167 cib.setBounds(110,100,30,30); 168 JCheckBox cib2=new JCheckBox("男"); 169 JCheckBox cib3=new JCheckBox("女"); 170 JButton cib_4=new JButton("确定"); 171 JButton cib_5=new JButton("取消"); 172 CreatJDialog a=new CreatJDialog(); 173 cib_4.addActionListener(new ActionListener() { 174 public void actionPerformed(ActionEvent e){ 175 new CreatJDialog().JDialog();; 176 } 177 178 }); 179 JPanel cl=new JPanel(); 180 cl.setPreferredSize(new Dimension(50,20)); 181 JPanel c2=new JPanel(); 182 JPanel c3=new JPanel(); 183 jf.setLayout(new GridLayout(3,1)); 184 c2.add(cib2); 185 c2.add(cib3); 186 cl.add(cib); 187 c3.add(cib_4); 188 c3.add(cib_5); 189 jf.add(cl); 190 jf.add(c2); 191 jf.add(c3); 192 193 jf.setVisible(true); 194 jf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 195 } 196 } 197 198 public class test { 199 200 public static void main(String args[]){ 201 new Enter().Enter(); 202 203 } 204 }

 

JFrame部分功能

标签:package   bsp   str   equals   static   import   完成   remove   text   

原文地址:https://www.cnblogs.com/TuTu-winer/p/10853088.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!