728x90
반응형
주문 프로그램 만들기
- 치킨 주문 프로그램 만들기
프로그램 GUI
전체 코드
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Bbq1 extends JFrame implements ActionListener{
JLabel l1,l2,l3;
JTextField tf1;
JPasswordField tf2;
JButton b1,b2;
Bbq1(){
super("login");
l1=new JLabel("BBQ");
l2=new JLabel("아이디"); tf1=new JTextField(10);
l3=new JLabel("비번"); tf2=new JPasswordField(10);
b1=new JButton("확인");
b1.addActionListener(this);
b2=new JButton("회원가입");
JPanel p1=new JPanel();
p1.setLayout(new FlowLayout());
p1.add("Center",l1);
JPanel p2=new JPanel();
p2.setLayout(new FlowLayout());
p2.add(l2); p2.add(tf1);
JPanel p3=new JPanel();
p3.setLayout(new FlowLayout());
p3.add(l3); p3.add(tf2);
JPanel p5=new JPanel();
p5.setLayout(new BorderLayout());
p5.add("North",p2); p5.add("South",p3);
JPanel p4=new JPanel();
p4.setLayout(new FlowLayout());
p4.add(b1); p4.add(b2);
this.setLayout(new BorderLayout());
this.add("North",p1);
this.add("Center",p5);
this.add("South",p4);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //3
//this.setSize(100,200);
this.pack();
this.setVisible(true);
}
public static void main(String[] args) {
new Bbq1();
}
@Override
public void actionPerformed(ActionEvent e) {
String id=tf1.getText();
char[] p=tf2.getPassword();
String pw=new String(p);
if(pw.equals("1234")) { //패스워드가 1234
new Bbq2(id);
this.setVisible(false);
} else {
l1.setText("비번확인");
}
} //action
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Bbq2 extends JFrame implements ActionListener{
JLabel l1,l2,l3;
JComboBox<String> jb1, jb2;
JRadioButton r1,r2;
JButton b1;
String id;
Bbq2(String id){
super(id+"주문하기");
this.id=id;
l1=new JLabel("메뉴"); jb1=new JComboBox<String>(); jb1.addItem("후라이드"); jb1.addItem("양념");
l2=new JLabel("사이드 메뉴"); jb2=new JComboBox<String>(); jb2.addItem("콜라"); jb2.addItem("사이다");
l3=new JLabel("파무침");
r1=new JRadioButton("선택",true); r2=new JRadioButton("미선택");
ButtonGroup p=new ButtonGroup();
p.add(r1); p.add(r2);
b1=new JButton("확인");
b1.addActionListener(this);
JPanel p1=new JPanel();
p1.setLayout(new FlowLayout());
p1.add(l1); p1.add(jb1);
JPanel p2=new JPanel();
p2.setLayout(new FlowLayout());
p2.add(l2); p2.add(jb2);
JPanel p3=new JPanel();
p3.setLayout(new FlowLayout());
p3.add(l3); p3.add(r1); p3.add(r2);
JPanel p4=new JPanel();
p4.setLayout(new FlowLayout());
p4.add(b1);
JPanel p5=new JPanel();
p5.setLayout(new BorderLayout());
p5.add("North",p1); p5.add("Center",p2); p5.add("South",p3);
this.setLayout(new BorderLayout());
this.add("North",p5); this.add("South",p4);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //3
//this.setSize(200,200);
this.pack();
this.setVisible(true);
}
public static void main(String[] args) {
new Bbq2("");
}
@Override
public void actionPerformed(ActionEvent arg0) {
String m1=(String)jb1.getSelectedItem();
String m2=(String)jb2.getSelectedItem();
String m3="선택";
if(r2.isSelected()) m3="미선택";
new Bbq3(id, m1, m2, m3);
this.setVisible(false);
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Bbq3 extends JFrame implements ActionListener{
JLabel l1,l2,l3;
JButton b;
Bbq3(String id, String m1, String m2, String m3){
super(id);
l1=new JLabel("메뉴 : "+m1, 0); //0 == JLabel.CENTER
l2=new JLabel("사이드 : "+m2, 0);
l3=new JLabel("파무침 : "+m3, 0);
b=new JButton("close");
b.addActionListener(this);
JPanel p=new JPanel();
p.setLayout(new BorderLayout());
p.add("North",l3); p.add("Center",b);
this.setLayout(new BorderLayout());
this.add("North", l1);
this.add("Center", l2);
this.add("South", p);
this.setDefaultCloseOperation(3);
this.setSize(300,300); //this.pack();
this.setVisible(true);
}
public static void main(String[] args) {
new Bbq3("","","","");
} //main
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
} //class
728x90
반응형