티스토리 뷰

package gui;


import javax.swing.*;

import javax.swing.event.*;

import java.awt.*;

import java.awt.event.*;


public class Testing extends JFrame{

//get 현재상태값

//is boolean return

//한줄 텍스트필드, 여러줄 텍스트에어리어

JFrame internalframe;

JLayeredPane mainPane;

JButton btLogin = new JButton("LOGIN");

JTextField txID = new JTextField();

JPasswordField txPass = new JPasswordField();

JLabel lbID = new JLabel("ID");

JLabel lbPass = new JLabel("Password");

JLabel lbMe = new JLabel("j0n9m1n1.com");

JButton btOK = new JButton("OK");

JButton btCancel = new JButton("Cancel");

JLabel lbLog = new JLabel("Message Log");

JTextArea taLog = new JTextArea("");

MyActionListener myBTListener = new MyActionListener();

public Testing() {

super("Main Frame");

setSize(600, 500);

Container c = getContentPane();

mainPane = new JLayeredPane();

c.setLayout(new BorderLayout());

mainPane.setLayout(new BorderLayout());;

c.add(btLogin, BorderLayout.SOUTH);

c.add(mainPane,  BorderLayout.CENTER);

mainPane.add(lbLog,  BorderLayout.NORTH);

mainPane.add(taLog,  BorderLayout.CENTER);

taLog.setEditable(false);

internalframe = new JFrame("Login Frame");

Container ic = internalframe.getContentPane();

ic.setLayout(new GridLayout(4,2));

ic.add(lbID);

ic.add(txID);

ic.add(lbPass);

ic.add(txPass);

ic.add(btOK);

ic.add(btCancel);

ic.add(lbMe);

btLogin.addActionListener(myBTListener);

btOK.addActionListener(myBTListener);

btCancel.addActionListener(myBTListener);

setVisible(true);

taLog.append("> System is initiated. \n");


}

public static void main(String[] args) {

Testing a = new Testing();

}

class MyActionListener implements ActionListener{

public void actionPerformed(ActionEvent e) {

JButton b = (JButton)e.getSource();

if(b.getText().equals("LOGIN")) {

if(internalframe.isVisible()==false) {

internalframe.setBounds(150,100, 250,140);

internalframe.setVisible(true);;

}

}

else if (b.getText().equals("OK")) {

internalframe.setVisible(false);

btLogin.setText("EXIT");

String enteredID = txID.getText();

taLog.append("> " + enteredID + " is entered this room. \n");

taLog.setEditable(true);

}

else if (b.getText().equals("Cancel")) {

internalframe.setVisible(false);

}

else if (b.getText().equals("EXIT")) {

System.exit(0);

}

}

}

}



댓글
댓글쓰기 폼