zuoye2.java

来自「主要完成一些窗口的建立」· Java 代码 · 共 79 行

JAVA
79
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. *//** * * @author ywt */import java.awt.*;import javax.swing.*;import java.awt.event.*;public class ZuoYe2 extends JFrame implements ActionListener{     JButton dialog,OK;     public JTextArea text;     public ZuoYe2(){     Container container= getContentPane();     container.setLayout(new BorderLayout());     container.add(text=new JTextArea(""),BorderLayout.CENTER);     container.add(dialog=new  JButton("dialog"),BorderLayout.NORTH);     dialog.addActionListener(this);    }  public static void main(String[] args){         ZuoYe2 frame=new  ZuoYe2();        frame.setTitle("example");        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        frame.setSize(400,250);        frame.setVisible(true);}    public void actionPerformed(ActionEvent e){         go g1=new go();        g1.a( this );      }    }class go implements ActionListener{  JLabel lab1,lab2;  JTextField text1,text2;  public JButton OK;  public  String s1,s2;   ZuoYe2 s;   public void a(ZuoYe2 o){     s=o;     JFrame  p2= new JFrame();     p2.setTitle("dialog");     p2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     p2.setSize(200,100);     p2.setVisible(true);     JPanel  p3= new JPanel();     p3.setLayout(new GridLayout(2,2));     p2.setLayout(new BorderLayout());     p3.add(lab1=new JLabel("name"));     p3.add(text1=new JTextField(""));     p3.add(lab2=new JLabel("PassWord"));     p3.add(text2=new JTextField(""));     System.out.println("adfsd");     p2.add(p3,BorderLayout.CENTER);     p2.add(OK=new JButton("OK"),BorderLayout.SOUTH);     OK.addActionListener(this);      }   public void actionPerformed(ActionEvent e){       if(e.getSource()==OK){                s1=text1.getText();          s2=text2.getText();          s.text.append("Name:"+s1+"\n");          s.text.append("PassWord"+s2);      }   } }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?