'javabasic'에 해당되는 글 15건

  1. 2010.08.04 채팅ver1.05
  2. 2010.08.04 chatting ver1.02
  3. 2010.07.30 채팅UI 2010.7.29
  4. 2010.07.23 chatting-frame ui
  5. 2010.07.22 채팅 UI
  6. 2010.07.22 자바강의2
  7. 2010.07.22 자바 강의
  8. 2010.07.16 계산기(자바)
  9. 2010.07.07 연습문제 3장 3번문제
  10. 2010.07.07 3장 2번문제

채팅ver1.05

javabasic 2010. 8. 4. 16:27

'javabasic' 카테고리의 다른 글

chatting ver1.02  (0) 2010.08.04
채팅UI 2010.7.29  (0) 2010.07.30
chatting-frame ui  (0) 2010.07.23
채팅 UI  (0) 2010.07.22
자바강의2  (0) 2010.07.22
Posted by 지화명이
,

chatting ver1.02

javabasic 2010. 8. 4. 00:34

'javabasic' 카테고리의 다른 글

채팅ver1.05  (0) 2010.08.04
채팅UI 2010.7.29  (0) 2010.07.30
chatting-frame ui  (0) 2010.07.23
채팅 UI  (0) 2010.07.22
자바강의2  (0) 2010.07.22
Posted by 지화명이
,

채팅UI 2010.7.29

javabasic 2010. 7. 30. 19:39

//2010.7.29 VER1.00
package sms.it;

import java.awt.*;
import java.awt.event.*;

class Exam_02_Sub extends Frame implements ActionListener {
 String str1="========================================================" +"\n"
       +"채팅 방에 오신것을 환영합니다.즐거운 시간되세요!!!!" + "\n"
       + "========================================================"+"\n";
 String str2="[방 참가인원]";
 
 private BorderLayout bl_a=new BorderLayout();
 private BorderLayout bl_change=new BorderLayout();//dlg_change
 private BorderLayout bl_send=new BorderLayout();//dlg_send
 
 private FlowLayout fl_change=new FlowLayout();
 private FlowLayout fl_send=new FlowLayout();
 private FlowLayout fl_send2=new FlowLayout();
 
 private Label label_a=new Label("부산IT직업학교 채팅프로그램입니다.");
 private Label label_color=new Label("색상선택");
 private Label label_change=new Label("바꿀 대화명:");
 private Label label_send1=new Label("대화명:");
 private Label label_send2=new Label("보낼 내용:");
 
 private Panel panel_south=new Panel();
 private Panel panel_north=new Panel();
 private Panel panel_east=new Panel();
 private Panel panel_center=new Panel();
 private Panel panel_south_sub1=new Panel();
 private Panel panel_south_sub2=new Panel();
 private Panel panel_change1=new Panel();//dlg_change
 private Panel panel_change2=new Panel();//dlg_change
 private Panel panel_send1=new Panel();//dlg_send
 private Panel panel_send2=new Panel();//dlg_send
 private Panel panel_send3=new Panel();//dlg_send
 
 private GridLayout gl_south=new GridLayout(2,1);
 private GridLayout glb_change=new GridLayout(2,1);//dlg_change
 private GridLayout glb_send=new GridLayout(3,1);//dlg_send
 
 private Choice choice_whisper=new Choice();
 private Choice choice_color=new Choice();
 
 private TextArea text_center=new TextArea(str1,30,70);
 private TextArea text_east=new TextArea(str2,30,20);
 private TextField text_south=new TextField("",40);
 private TextField text_change=new TextField("",10);
 private TextField text_send1=new TextField("",10);
 private TextField text_send2=new TextField("",40);
 
 private Button btn_eraser=new Button("화면지우기");
 private Button btn_help=new Button("도움말");
 private Button btn_exit=new Button("나가기");
 private Button btn_msg=new Button("쪽지보내기");
 private Button btn_change=new Button("대화명바꾸기");
 private Button btn_end=new Button("방나가기");
 private Button btn_dlg_ok=new Button("완료");
 private Button btn_dlg_cancel1=new Button("취소");
 private Button btn_dlg_send=new Button("보내기");
 private Button btn_dlg_cancel2=new Button("취소하기");
 //Dialog
 private Dialog dlg_change=new Dialog(this,"대화명 바꾸기",true);
 private Dialog dlg_send=new Dialog(this,"쪽지보내기",true);
 
 
 public Exam_02_Sub(String title){
  super(title);
  
  this.init();
  this.start();//event,thread adding
  
  this.setSize(800, 600);
  Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
  Dimension frm=super.getSize();
  int xpos=(int)(screen.getWidth()/2-frm.getWidth()/2);
  int ypos=(int)(screen.getHeight()/2-frm.getHeight()/2);
  super.setLocation(xpos,ypos);
  super.setResizable(false);
  super.setVisible(true);
 
 }
 public void init(){
    
  this.setLayout(bl_a);
    
  panel_north.add(label_a);
  this.add("North",panel_north);
  panel_north.setBackground(new Color(150,135,0));
  
  panel_south.setLayout(gl_south);
  choice_whisper.add("귓속말선택");
  panel_south_sub1.add(choice_whisper);
  panel_south_sub1.add(text_south);
  panel_south_sub1.add(btn_eraser);
  panel_south_sub1.add(btn_help);
  panel_south_sub1.add(btn_exit);
  panel_south.add(panel_south_sub1);
  panel_south_sub2.add(label_color);
  choice_color.add("빨강");
  choice_color.add("파랑");
  choice_color.add("노랑");
  choice_color.add("녹색");
  panel_south_sub2.add(choice_color);
  panel_south_sub2.add(btn_msg);
  panel_south_sub2.add(btn_change);
  panel_south_sub2.add(btn_end);
  panel_south.add(panel_south_sub2);
  this.add("South",panel_south);
  panel_south.setBackground(new Color(150,135,0));
  
  panel_east.add(text_east);
  this.add("East",panel_east);
  
  
  this.add("Center",text_center);
  
  
  //dialog_change
  dlg_change.setLayout(bl_change);
  panel_change1.setLayout(fl_change);
  panel_change1.add(label_change);
  panel_change1.add(text_change);
  panel_change2.add(btn_dlg_ok);
  panel_change2.add(btn_dlg_cancel1);
  dlg_change.add("North",panel_change1);
  dlg_change.add("South",panel_change2);
  
  //dialog_send
  dlg_send.setLayout(bl_send);
  dlg_send.setLayout(glb_send);
  panel_send1.setLayout(fl_send);
  panel_send2.setLayout(fl_send2);
  panel_send1.add(label_send1,"LEFT");
  panel_send1.add(text_send1);
  panel_send2.add(label_send2);
  panel_send2.add(text_send2);
  panel_send3.add(btn_dlg_send);
  panel_send3.add(btn_dlg_cancel2);
  dlg_send.add("North",panel_send1);
  dlg_send.add("Center",panel_send2);
  dlg_send.add("South",panel_send3);
  
  this.setVisible(true);
  
 }
 public void start(){
  btn_eraser.addActionListener(this);
  btn_help.addActionListener(this);
  btn_exit.addActionListener(this);
  btn_msg.addActionListener(this);
  btn_change.addActionListener(this);
  btn_end.addActionListener(this);
  btn_dlg_ok.addActionListener(this);
  btn_dlg_cancel1.addActionListener(this);
  btn_dlg_send.addActionListener(this);
  btn_dlg_cancel2.addActionListener(this);
  
  this.addWindowListener(new WindowAdapter() {
   public void windowClosing(WindowEvent e){
    System.exit(0);
   }
  });
  dlg_change.addWindowListener(new WindowAdapter() {
   public void windowClosing(WindowEvent e){
    dlg_change.setVisible(false);
   }
  });
  dlg_send.addWindowListener(new WindowAdapter() {
   public void windowClosing(WindowEvent e){
    dlg_send.setVisible(false);
   }
  });
 }
 public void actionPerformed(ActionEvent e){
  if(e.getSource()==btn_eraser){
   
  }
  else if(e.getSource()==btn_help){
   
  }
  else if(e.getSource()==btn_exit){
   System.exit(0);
  }
  else if(e.getSource()==btn_msg){
   dlg_send.setLocation(200, 400);
   dlg_send.setSize(400,160);
   dlg_send.setVisible(true);
  }
  else if(e.getSource()==btn_change){
   dlg_change.setLocation(200, 200);
   dlg_change.setSize(200,120);
   dlg_change.setVisible(true);
  }
  else if(e.getSource()==btn_end){
   
  }
  else if(e.getSource()==btn_dlg_ok){
   
  }
  else if(e.getSource()==btn_dlg_cancel1){
   dlg_change.setVisible(false);
  }
  else if(e.getSource()==btn_dlg_send){
   
  }
  else if(e.getSource()==btn_dlg_cancel2){
   dlg_send.setVisible(false);
  }
  
 }
 
}

public class ChattingProgram {

 public static void main(String[] args) {
  Exam_02_Sub ex=new Exam_02_Sub("채팅 프로그램");

 }

}


 
 

'javabasic' 카테고리의 다른 글

채팅ver1.05  (0) 2010.08.04
chatting ver1.02  (0) 2010.08.04
chatting-frame ui  (0) 2010.07.23
채팅 UI  (0) 2010.07.22
자바강의2  (0) 2010.07.22
Posted by 지화명이
,

chatting-frame ui

javabasic 2010. 7. 23. 17:17

//chatting....
import java.awt.*;
import java.awt.event.*;

public class ChattFrame extends Frame {
    private Panel northPanel = new Panel();
    private Panel southPanel = new Panel();
    private Panel eastPanel = new Panel();
    private Panel centerPanel = new Panel();

    public static void main (String[] args) {
 ChattFrame chat=new ChattFrame();
 chat.go();
 
    }
    public void go(){
 
 Frame aframe = new Frame();
  
 aframe.add(BorderLayout.CENTER,centerPanel);
 aframe.add(BorderLayout.NORTH,northPanel);
 //
 aframe.add(BorderLayout.SOUTH,southPanel);
 southPanel.setLayout (new BorderLayout());
 Panel southa = new Panel();
 Panel southb = new Panel();
 southPanel.add(southa,BorderLayout.NORTH);
 southPanel.add(southb,BorderLayout.SOUTH);

 aframe.setSize(800,600);
 aframe.setVisible(true);
 
  // centerPanel에  TextArea생성하여 배치한다.
        //centerPanel.setBackground(Color.WHITE);
 TextArea ta1=new TextArea("////////////// 채팅방에 들어 오신것을 환영합니다 ////////////////",30,60);
 centerPanel.add (ta1);

 // eastPanel 텍스트에리어를 생성하여 배치한다.
        TextArea ta2=new TextArea("[참가인원]",20,20);
 aframe.add(BorderLayout.EAST,ta2);
        
 
 //north 배치
 Label titleLabelnorth = new Label ("부산it직업학교 채팅 프로그램");
 northPanel.setBackground(Color.ORANGE);
        northPanel.setLayout (new FlowLayout());
        northPanel.add (titleLabelnorth);
 
 //south 배치
 //Label titleLabelnorth1 = new Label ("Whisper:");
 southa.setBackground(Color.ORANGE);
        southa.setLayout (new FlowLayout());
        //southa.add (titleLabelnorth1);

 Choice aChoice = new Choice();
 aChoice.add("귓속말선택");
 southa.add(aChoice);

 //southPanel에 TextField 배치
 TextField tf1=new TextField("",50);
 southa.add(tf1);
 
 
 southb.setBackground(Color.yellow);
        southb.setLayout (new FlowLayout());
        //southb.add (titleLabelnorth2);

 //southPanel에 버튼 배치
       Button[] southButton = new Button[7];
        southButton[0] = new Button ("대화방개설");
 southButton[0].addActionListener (new southButtonHandler(southButton[0]));
        southb.add (southButton[0]);
 southButton[1] = new Button ("대화방참여");
 southButton[1].addActionListener (new southButtonHandler(southButton[1]));
        southb.add (southButton[1]);
 southButton[2] = new Button ("대화명변경");
 southButton[2].addActionListener (new southButtonHandler(southButton[2]));
        southb.add (southButton[2]);
 southButton[3] = new Button ("쪽지보내기");
 southButton[3].addActionListener (new southButtonHandler(southButton[3]));
        southb.add (southButton[3]);
 southButton[4] = new Button ("화면지우기");
 southButton[4].addActionListener (new southButtonHandler(southButton[4]));
        southa.add (southButton[4]);
 southButton[5] = new Button ("도움말");
 southButton[5].addActionListener (new southButtonHandler(southButton[5]));
        southa.add (southButton[5]);
 southButton[6] = new Button ("나가기");
 southButton[6].addActionListener (new southButtonHandler(southButton[6]));
        southa.add (southButton[6]);
 Label southLabel1 = new Label ("부산it직업학교 채팅 프로그램");
 southb.add(southLabel1);
    }   
    class southButtonHandler implements ActionListener {
     Button aButton;

     public southButtonHandler (Button paraButton) {aButton = paraButton;}

     public void actionPerformed (ActionEvent e) {
  if(((Button)e.getSource()).getLabel()=="대화방개설"){
   aButton.setBackground (Color.yellow);
  }
  else if(((Button)e.getSource()).getLabel()=="대화방참여"){
   aButton.setBackground (Color.blue);
  }
  else if(((Button)e.getSource()).getLabel()=="대화명변경"){
   aButton.setBackground (Color.yellow);
   
   FlowLayout flow1=new FlowLayout();
   setLayout (flow1);
   
   Label titleLabel2 = new Label ("대화명을 변경합니다");
   TextField chtext=new TextField(20);
          setBackground (Color.red);
   addWindowListener (new WindowHandler());
   add(titleLabel2);
   add(chtext);
   
   setVisible (true);
  }
  else if(((Button)e.getSource()).getLabel()=="쪽지보내기"){
   aButton.setBackground (Color.orange);
  }
  else if(((Button)e.getSource()).getLabel()=="화면지우기"){
   aButton.setBackground (Color.green);
  }
  else if(((Button)e.getSource()).getLabel()=="도움말"){
   aButton.setBackground (Color.yellow);
  }
  else if(((Button)e.getSource()).getLabel()=="나가기"){
   aButton.setBackground (Color.red);
   System.exit(0);

  }
  
     }
 
   
    } 
    // 윈도우를 닫기위한 이벤트 청취자
    class WindowHandler extends WindowAdapter {
        public void windowClosing (WindowEvent e) {
            if (e.getID() == WindowEvent.WINDOW_CLOSING) {
                setVisible (false);
                System.exit (0);
            }
        }
    }

}

'javabasic' 카테고리의 다른 글

chatting ver1.02  (0) 2010.08.04
채팅UI 2010.7.29  (0) 2010.07.30
채팅 UI  (0) 2010.07.22
자바강의2  (0) 2010.07.22
자바 강의  (0) 2010.07.22
Posted by 지화명이
,

채팅 UI

javabasic 2010. 7. 22. 16:00

/* Panel을 이용하여 화면을 배치하는 프로그램. 화면은 BorderLayout으로 설정된다. 각 영역은 Panel 객체를 이용하여 다시 각각 독립적인 구성으로 배치한다. */

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class ChattingPanel extends Applet {
    // 패널을 생성한다.
    private Panel northPanel = new Panel();
    private Panel southPanel = new Panel();
    private Panel eastPanel = new Panel();
    private Panel centerPanel = new Panel();
   

    public void init() {
        BorderLayout aBorder = new BorderLayout();
        setLayout (aBorder);

        //  패널을 윈도우에 배치한다.
        add (northPanel, BorderLayout.NORTH);
        add (southPanel, BorderLayout.SOUTH);
 add (eastPanel, BorderLayout.EAST);
        add (centerPanel, BorderLayout.CENTER);
    

 // northPanel에 Labele 을 생성
 Label titleLabelnorth = new Label ("부산it직업학교 채팅 프로그램");
 northPanel.setBackground(Color.ORANGE);
        northPanel.setLayout (new FlowLayout());
        northPanel.add (titleLabelnorth);

        // centerPanel에  TextArea생성하여 배치한다.
        centerPanel.setLayout (new BorderLayout());
 centerPanel.setBackground(Color.WHITE);
 TextArea ta1=new TextArea("////////////// 채팅방에 들어 오신것을 환영합니다 ////////////////");
 //Button centerCButton = new Button ("Center Button");
        centerPanel.add (ta1, BorderLayout.CENTER);

        // southPanel에 Choice 배치한다.
 //FlowLayout aFlow = new FlowLayout();
        //southPanel.setLayout (aFlow);

 Choice aChoice = new Choice();
 aChoice.add("귓속말선택");
 southPanel.add(aChoice);
 
 //southPanel에 TextField 배치
 TextField tf1=new TextField("",50);
 southPanel.add(tf1,BorderLayout.SOUTH);
 southPanel.setBackground(Color.ORANGE);
 GridLayout aGrid = new GridLayout (2,1);
        southPanel.setLayout (aGrid );

 //southPanel에 버튼 배치
       Button[] southButton = new Button[7];
        southButton[0] = new Button ("대화방개설");
 southButton[0].addActionListener (new southButtonHandler(southButton[0]));
        southPanel.add (southButton[0]);
 southButton[1] = new Button ("대화방참여");
 southButton[1].addActionListener (new southButtonHandler(southButton[1]));
        southPanel.add (southButton[1]);
 southButton[2] = new Button ("대화명변경");
 southButton[2].addActionListener (new southButtonHandler(southButton[2]));
        southPanel.add (southButton[2]);
 southButton[3] = new Button ("쪽지보내기");
 southButton[3].addActionListener (new southButtonHandler(southButton[3]));
        southPanel.add (southButton[3]);
 southButton[4] = new Button ("화면지우기");
 southButton[4].addActionListener (new southButtonHandler(southButton[4]));
        southPanel.add (southButton[4]);
 southButton[5] = new Button ("도움말");
 southButton[5].addActionListener (new southButtonHandler(southButton[5]));
        southPanel.add (southButton[5]);
 southButton[6] = new Button ("나가기");
 southButton[6].addActionListener (new southButtonHandler(southButton[6]));
        southPanel.add (southButton[6]);
 Label southLabel1 = new Label ("부산it직업학교 채팅 프로그램");
 southPanel.add(southLabel1);

        // eastPanel 텍스트에리어를 생성하여 배치한다.
        eastPanel.setLayout (new GridLayout ());
 TextArea ta2=new TextArea("[참가인원]",20,20);
        eastPanel.add (ta2,BorderLayout.EAST);
          
    }

    class southButtonHandler implements ActionListener {
     Button aButton;

     public southButtonHandler (Button paraButton) {aButton = paraButton;}

     public void actionPerformed (ActionEvent e) {
  if(((Button)e.getSource()).getLabel()=="대화방개설"){
   aButton.setBackground (Color.yellow);
  }
  else if(((Button)e.getSource()).getLabel()=="대화방참여"){
   aButton.setBackground (Color.blue);
  }
  else if(((Button)e.getSource()).getLabel()=="대화명변경"){
   aButton.setBackground (Color.yellow);
   
   
  }
  else if(((Button)e.getSource()).getLabel()=="쪽지보내기"){
   aButton.setBackground (Color.orange);
  }
  else if(((Button)e.getSource()).getLabel()=="화면지우기"){
   aButton.setBackground (Color.green);
  }
  else if(((Button)e.getSource()).getLabel()=="도움말"){
   aButton.setBackground (Color.yellow);
  }
  else if(((Button)e.getSource()).getLabel()=="나가기"){
   aButton.setBackground (Color.red);
   System.exit(0);

  }
     }
   
    }
 
}

'javabasic' 카테고리의 다른 글

채팅UI 2010.7.29  (0) 2010.07.30
chatting-frame ui  (0) 2010.07.23
자바강의2  (0) 2010.07.22
자바 강의  (0) 2010.07.22
계산기(자바)  (0) 2010.07.16
Posted by 지화명이
,

자바강의2

javabasic 2010. 7. 22. 15:43

'javabasic' 카테고리의 다른 글

chatting-frame ui  (0) 2010.07.23
채팅 UI  (0) 2010.07.22
자바 강의  (0) 2010.07.22
계산기(자바)  (0) 2010.07.16
연습문제 3장 3번문제  (0) 2010.07.07
Posted by 지화명이
,

자바 강의

javabasic 2010. 7. 22. 15:42

'javabasic' 카테고리의 다른 글

채팅 UI  (0) 2010.07.22
자바강의2  (0) 2010.07.22
계산기(자바)  (0) 2010.07.16
연습문제 3장 3번문제  (0) 2010.07.07
3장 2번문제  (0) 2010.07.07
Posted by 지화명이
,

계산기(자바)

javabasic 2010. 7. 16. 15:11


// GridBagLayout을 이용하여 계산기 프로그램

import java.awt.*;
import java.awt.event.*;

public class Calculator extends Frame{
 GridBagLayout layout = new GridBagLayout();
 GridBagConstraints constraints = new GridBagConstraints();
 Button b0, b1, b2, b3, b4, b5, b6, b7, b8, b9,
        bPlus, bMinus, bMul, bDiv, bEqual, bClear, bDot;
        Label T1;
   

   public static void main (String[] args) {
         Calculator aWindow = new Calculator ();
 }//메인끗

 public Calculator () {
        setTitle ("GridBagLayout Window");
        setLayout (layout);
 
        constraints.fill = GridBagConstraints.BOTH;
        constraints.insets = new Insets (5, 5, 5, 5);
        constraints.weightx = constraints.weighty = 1.0;
     
        //버튼을 생성하여 위치를 정한 다음, addComponent()를 호출한다.
 T1 =  new Label("",Label.RIGHT);

 addComponent (0, 0, 4, 1, T1);

        addComponent (0, 1, 1, 1, bClear = new Button ("CL"));

        addComponent (0, 2, 1, 1, b1 = new Button ("1"));

        addComponent (0, 3, 1, 1, b4 = new Button ("4"));
        addComponent (0, 4, 1, 1, b7 = new Button ("7"));
        addComponent (0, 5, 2, 1, b0 = new Button ("0"));

        addComponent (1, 1, 1, 1, bDiv = new Button ("/"));
        addComponent (1, 2, 1, 1, b2 = new Button ("2"));
        addComponent (1, 3, 1, 1, b5 = new Button ("5"));
        addComponent (1, 4, 1, 1, b8 = new Button ("8"));
     
        addComponent (2, 1, 1, 1, bMul = new Button ("*"));
        addComponent (2, 2, 1, 1, b3 = new Button ("3"));
        addComponent (2, 3, 1, 1, b6 = new Button ("6"));
        addComponent (2, 4, 1, 1, b9 = new Button ("9"));
        addComponent (2, 5, 1, 1, bDot = new Button ("."));
     
        addComponent (3, 1, 1, 1, bMinus = new Button ("-"));
        addComponent (3, 2, 1, 2, bPlus = new Button ("+"));
        addComponent (3, 4, 1, 2, bEqual = new Button ("="));

 bClear.addActionListener(new scaButtonHandler(T1));
 b1.addActionListener(new scaButtonHandler(T1));
 b2.addActionListener(new scaButtonHandler(T1));
 b3.addActionListener(new scaButtonHandler(T1));
 b4.addActionListener(new scaButtonHandler(T1));
 b5.addActionListener(new scaButtonHandler(T1));
 b6.addActionListener(new scaButtonHandler(T1));
 b7.addActionListener(new scaButtonHandler(T1));
 b8.addActionListener(new scaButtonHandler(T1));
 b9.addActionListener(new scaButtonHandler(T1));
 b0.addActionListener(new scaButtonHandler(T1));
 bDot.addActionListener(new scaButtonHandler(T1));

 bMul.addActionListener(new scaButtonHandler(T1));
 bPlus.addActionListener(new scaButtonHandler(T1));
 bMinus.addActionListener(new scaButtonHandler(T1));
 bDiv.addActionListener(new scaButtonHandler(T1));
 T1.setText("0");
 bEqual.addActionListener(new scaButtonHandler(T1));
 FlowLayout Flow1 = new FlowLayout();
 Flow1.setAlignment(FlowLayout.RIGHT);
        addWindowListener (new WindowHandler());
        setBounds (10,10,250,300);
        setVisible (true);
    }//생성자 끗
 
    // 인수로 컴포넌트와 위치를 넘겨받아, 윈도우에 추가한다.
    public void addComponent (int x, int y, int w, int h, Component theComponent) {
        constraints.gridx = x;
        constraints.gridy = y;
        constraints.gridwidth = w;
        constraints.gridheight = h;
        layout.setConstraints (theComponent, constraints);
        add (theComponent);
    }

    class WindowHandler extends WindowAdapter {
        public void windowClosing (WindowEvent e) {
            setVisible (false);
            dispose();
            System.exit (0);
        }
    }

 int FirstValue=0;
 int SecondValue=0;
 int TempValue=0;

 

}//calculator끗

/*
class ButtonControl implements ActionListener{
   public void actionPerformed(ActionEvent ae){
 
  T1.setText(T1.getText() + ((Button)ae.getSource()).getLabel() );

    }//액션펄폼드끗
}//버튼콘트롤 끗/
*/


class scaButtonHandler implements ActionListener{
   Label T1;
   String StText=new String("0");

   static Double TempNumber = new Double(0);
   static Double FirstNumber = new Double(0);
   static Double SecondNumber = new Double(0);
   static Double ReseltNumber = new Double(0);
   static int iReseltNumber = 0;
   static char oper = 0;
   static int swit = 0;
   static int lapperswit = 0;
   static int Reselt=0;
   scaButtonHandler(Label paraField){
 T1 = paraField;
   }
   Double Lapper(Double FNmb,Double SNmb,char oper){
 if(oper == '+'){
  return (FNmb+SNmb);
 }
 else if(oper == '-'){
  return (FNmb-SNmb);
 }
 else if(oper == '/'){
  if(SNmb==0) return 0.0;  
  else return (FNmb/SNmb);
 }
 else if(oper == '*'){
  return (FNmb*SNmb);
 }
 return 0.0;
   }
   public void actionPerformed(ActionEvent ae){

  if(((Button)ae.getSource()).getLabel()=="="){
    
    if(FirstNumber==0) ReseltNumber = Lapper(ReseltNumber,SecondNumber,oper);
    else
    {
     SecondNumber = Double.parseDouble(T1.getText());
     ReseltNumber = Lapper(FirstNumber,SecondNumber,oper);
    }
    FirstNumber = 0.0;
    if(ReseltNumber%1==0) T1.setText(ReseltNumber.intValue()+"");
    else T1.setText(ReseltNumber+"");
    Reselt=1;
  }
  else if(((Button)ae.getSource()).getLabel()=="+"){
   if(FirstNumber == 0)
   {
    FirstNumber = Double.parseDouble(T1.getText());
    lapperswit=1;
    T1.setText("0");
    oper = '+';
    swit = 0;
   }
   else
   {
    if(lapperswit==0)
    {
     SecondNumber = Double.parseDouble(T1.getText()); 
     FirstNumber = Lapper(FirstNumber,SecondNumber,oper);
     if(FirstNumber%1==0) T1.setText(FirstNumber.intValue()+"");
     else T1.setText(FirstNumber+"");
     lapperswit=1;
     oper = '+';
    }
   }
  }
  else if(((Button)ae.getSource()).getLabel()=="-"){
   if(FirstNumber == 0)
   {
    FirstNumber = Double.parseDouble(T1.getText());
    lapperswit=1;
    T1.setText("0");
    oper = '-';
    swit = 0;
   }
   else
   {
    if(lapperswit==0)
    {
     SecondNumber = Double.parseDouble(T1.getText()); 
     FirstNumber = Lapper(FirstNumber,SecondNumber,oper);
     if(FirstNumber%1==0) T1.setText(FirstNumber.intValue()+"");
     else T1.setText(FirstNumber+"");
     lapperswit=1;
     oper = '-';
    }
   }
  }
  else if(((Button)ae.getSource()).getLabel()=="*"){
   if(FirstNumber == 0)
   {
    FirstNumber = Double.parseDouble(T1.getText());
    lapperswit=1;
    T1.setText("0");
    oper = '*';
    swit = 0;
   }
   else
   {
    if(lapperswit==0)
    {
     SecondNumber = Double.parseDouble(T1.getText()); 
     FirstNumber = Lapper(FirstNumber,SecondNumber,oper);
     if(FirstNumber%1==0) T1.setText(FirstNumber.intValue()+"");
     else T1.setText(FirstNumber+"");
     lapperswit=1;
     oper = '*';
    }
   }
  }
  else if(((Button)ae.getSource()).getLabel()=="/"){
   if(FirstNumber == 0)
   {
    FirstNumber = Double.parseDouble(T1.getText());
    lapperswit=1;
    T1.setText("0");
    oper = '/';
    swit = 0;
   }
   else
   {
    if(lapperswit==0)
    {
     SecondNumber = Double.parseDouble(T1.getText()); 
     FirstNumber = Lapper(FirstNumber,SecondNumber,oper);
     if(FirstNumber%1==0) T1.setText(FirstNumber.intValue()+"");
     else T1.setText(FirstNumber+"");
     lapperswit=1;
     oper = '/';
    }
   }   
  }
  // "."을 눌럿을경우
  else if(((Button)ae.getSource()).getLabel()=="."){
   if(swit==0)
   {
    T1.setText(T1.getText() +((Button)ae.getSource()).getLabel()+"0");
    swit = 1;
   }
  }
  // "CL"을 눌럿을경우
  else if(((Button)ae.getSource()).getLabel()=="CL"){
   T1.setText("0");
   swit = 0;
   lapperswit=0;
   TempNumber = 0.0;
   FirstNumber = 0.0;
   SecondNumber = 0.0;
   ReseltNumber =  0.0;;
   TempNumber = Double.parseDouble(T1.getText());
  }
  // 숫자를 눌럿을경우
  else if(((Button)ae.getSource()).getLabel()=="0"){
   if(Double.parseDouble(T1.getText())!=0)
   {
    T1.setText(T1.getText() +((Button)ae.getSource()).getLabel());
    TempNumber = Double.parseDouble(T1.getText());
   }
  }
  else
  {
   if(Reselt==1)
   {
    T1.setText("0");
    Reselt=0;
   }
   if(lapperswit==1)
   {
    T1.setText("0");
    lapperswit=0;
   }
   if(Double.parseDouble(T1.getText())!=0)
   {
    if((Double.parseDouble(T1.getText())%1)==0)
    {
     if(swit==1)
     {    
      T1.setText((int)(Double.parseDouble(T1.getText())/1) +"."+((Button)ae.getSource()).getLabel());
      TempNumber = Double.parseDouble(T1.getText()); 
     }
     else
     {
      T1.setText(T1.getText()+((Button)ae.getSource()).getLabel());
      TempNumber = Double.parseDouble(T1.getText());
     }  
    }
    else
    {
     T1.setText(T1.getText()+((Button)ae.getSource()).getLabel());
     TempNumber = Double.parseDouble(T1.getText());
    } 
   }
   else
   {
    if(swit==1)
    {
     T1.setText("0." +((Button)ae.getSource()).getLabel());
     TempNumber = Double.parseDouble(T1.getText()); 
    }    
    else
    {
     T1.setText(((Button)ae.getSource()).getLabel());
     TempNumber = Double.parseDouble(T1.getText());   
    }
   }
  }
    
  
    }//액션펄폼드끗


}//버튼콘트롤 끗/

 

'javabasic' 카테고리의 다른 글

자바강의2  (0) 2010.07.22
자바 강의  (0) 2010.07.22
연습문제 3장 3번문제  (0) 2010.07.07
3장 2번문제  (0) 2010.07.07
연습문제3장1번문제  (0) 2010.07.07
Posted by 지화명이
,

3번문제) 계산기프로그램으로써 사용자로부터 두수를 입력받고 연산값을 입력받아 해당 결과를    제출하는 프로그램을 짜라. (5번을 선택할 때까지 프로그램은 계속된다...)


import java.io.*;


  

class OperExm{
 public static void main(String args[]) throws IOException{

  System.out.println("메뉴에서 고르세요 ~~~~");
  System.out.println("1.덧셈");
  System.out.println("2.뺄셈");
  System.out.println("3.곱셈");
  System.out.println("4.나눗셈");
  System.out.println("5.나가기");

  BufferedReader stdin=new BufferedReader
    (new InputStreamReader(System.in));
  int num1,num2,choose;
  
  System.out.print("Enter the number : ");

  while(true){
  choose = Integer.parseInt (stdin.readLine());

  
  System.out.print("Enter the first number : ");
   num1 = Integer.parseInt (stdin.readLine());

         System.out.print ("Enter the second number : ");
         num2 = Integer.parseInt (stdin.readLine());

         switch(choose){
  case 1:
   System.out.println(num1+"+"+num2+"="+(num1+num2));
   break;
  case 2:
   System.out.println(num1+"-"+num2+"="+(num1-num2));
   break;
  case 3:
   System.out.println(num1+"*"+num2+"="+(num1*num2));
   break;
  case 4:
   System.out.println(num1+"/"+num2+"="+(num1/num2));
   break;

  }//switch
  System.out.println();
 
  System.out.println("메뉴에서 고르세요 ~~~~");
  System.out.println("1.덧셈");
  System.out.println("2.뺄셈");
  System.out.println("3.곱셈");
  System.out.println("4.나눗셈");
  System.out.println("5.나가기");

  System.out.print("Enter the number : ");
  choose = Integer.parseInt (stdin.readLine());
  if(choose==5){
   break;
  }
  
  }//While
 }//main

}//OperExm

'javabasic' 카테고리의 다른 글

자바 강의  (0) 2010.07.22
계산기(자바)  (0) 2010.07.16
3장 2번문제  (0) 2010.07.07
연습문제3장1번문제  (0) 2010.07.07
Runnable 사용법  (0) 2010.07.06
Posted by 지화명이
,

3장 2번문제

javabasic 2010. 7. 7. 09:14

2번문제) 구구단 출력 시켜라
===================================
import java.io.*;
import java.lang.*;

class Gugudan{
 public static void main(String[] args){
 // for(int i=2;i<=9;++i)
 // {
 int i=2;
   for(int j=1;9>=j;++j)
   {
    for(int k=0;k<8;++k){
    //System.out.print((i+k)+"*"+j+"="+((i+k)*j)+"  ");
    System.out.printf("%d*%d=%2d ",(i+k),j,((i+k)*j));
    }//int k
    System.out.println();
   }//int j
   System.out.println();
 // }//int i 

 }//main

}//class

'javabasic' 카테고리의 다른 글

계산기(자바)  (0) 2010.07.16
연습문제 3장 3번문제  (0) 2010.07.07
연습문제3장1번문제  (0) 2010.07.07
Runnable 사용법  (0) 2010.07.06
Thread 사용법  (0) 2010.07.06
Posted by 지화명이
,