import java.awt.Button;
import java.awt.Choice;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
class WindowClose extends WindowAdapter{
public void windowClosing(WindowEvent we){
System.exit(0);
}
}
class MyFrame extends Frame implements ActionListener{
Button b1,b2;
MyFrame(){}
MyFrame(String t) {
setTitle(t);
b1 = new Button("회원리스트");
b2 = new Button("직원리스트");
}
void addComponent() {
add(b1);
add(b2);
}
void registerEvent() {
b1.addActionListener(this); //회원리스트 클릭이벤트
b2.addActionListener(this); //직원리스트 클릭이벤트
this.addWindowListener(new WindowClose()); //창닫기 이벤트
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand()=="회원리스트"){ //회원리스트 클릭하면 새프레임뜸
this.setVisible(false);
newFrame1 f=new newFrame1("회원리스트",this);
f.setLayout(new FlowLayout());
f.setVisible(true);
f.setBounds(750, 250, 200, 200);
f.addComponent();
f.registerEvent();
}else{
this.setVisible(false);
newFrame2 f=new newFrame2("직원리스트",this);
f.setLayout(new FlowLayout());
f.setVisible(true);
f.setBounds(750, 250, 200, 200);
f.addComponent();
f.registerEvent();
}
}
}
class newFrame1 extends MyFrame implements ActionListener{
Choice c;
Button b;
MyFrame f;
newFrame1(String t,MyFrame f) {
setTitle(t);
this.f=f;
c = new Choice();
b= new Button("돌아가기");
try{
Class.forName("oracle.jdbc.OracleDriver");
String url="jdbc:oracle:thin:@//localhost:1521/xe";
String id="scott";
String pw="tiger";
Connection conn=DriverManager.getConnection(url,id,pw);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select id from seoulit");
Statement stmt1=conn.createStatement();
ResultSet rs1=stmt1.executeQuery("select count(*) from seoulit");
boolean b=rs.next();
boolean b2=rs1.next();
int count=Integer.parseInt(rs1.getString(1));
System.out.println(b); // true
for(int w=1;w<=count;w++){
String s=rs.getString(1);
c.add(s);
rs.next();
}
}catch(Exception e){
System.out.println("DB연동실패");
}
}
void addComponent() {
add(c);
add(b);
}
void registerEvent() {
this.addWindowListener(new WindowClose());
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
this.dispose();
f.setVisible(true);//되돌리기 이벤트
}
}
class newFrame2 extends MyFrame implements ActionListener{
Choice c;
Button b;
MyFrame f;
newFrame2(String t,MyFrame f) {
this.f=f;
setTitle(t);
c = new Choice();
b= new Button("돌아가기");
try{
Class.forName("oracle.jdbc.OracleDriver");
String url="jdbc:oracle:thin:@//localhost:1521/xe";
String id="scott";
String pw="tiger";
Connection conn=DriverManager.getConnection(url,id,pw);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select ename from emp");
Statement stmt1=conn.createStatement();
ResultSet rs1=stmt1.executeQuery("select count(*) from emp");
boolean b=rs.next();
boolean b2=rs1.next();
int count=Integer.parseInt(rs1.getString(1));
System.out.println(b); // true
for(int w=1;w<=count;w++){
String s=rs.getString(1);
c.add(s);
rs.next();
}
}catch(Exception e){
System.out.println("DB연동실패");
}
}
void addComponent() {
add(c);
add(b);
}
void registerEvent() {
this.addWindowListener(new WindowClose());
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e){ //되돌리기 이벤트
this.dispose();
f.setVisible(true);
}
}
class B {
public static void main(String args[]){
MyFrame f = new MyFrame("구민정");
f.setLayout(new FlowLayout());
f.setVisible(true);
f.setBounds(700, 200, 300, 300);
f.registerEvent();
f.addComponent();
}
}
'개발하자 > JAVA문제풀이' 카테고리의 다른 글
15.01.21 달력과제 2차(awt) (0) | 2015.01.21 |
---|---|
15.01.20 달력과제 1차(콘솔창출력) (0) | 2015.01.20 |
2015.01.08 awt 사칙연산 과제 (0) | 2015.01.08 |
묻지마정렬(학생의 반과 번호) (0) | 2015.01.06 |
2진수 IP주소를 10진수로 바꾸기 (0) | 2015.01.06 |