2009년 7월 22일 수요일

AWT를 이용한 간단한 - 계산기 -

import java.awt.Frame;
import java.awt.TextField;
import java.awt.Button;
import java.awt.Panel;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.Color;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Calculator extends Frame implements WindowListener, ActionListener{
 TextField result;
 Button[] button;
 boolean num_state = true;
 boolean operator_state=true;
 String op_temp;
 String num_temp;

 public void init() {
  result = new TextField("0", 30);
  result.setEditable(false);
  String[] buttonTitle = {"7", "8", "9", "/",
             "4", "5", "6", "*",
             "1", "2", "3", "-",
             "C", "0", "=", "+"};
  button = new Button[16];
  Panel p = new Panel();

  p.setLayout(new GridLayout(4,4,3,3));

  for (int i=0; i<button.length; i++ ) {
   button[i] = new Button(buttonTitle[i]);
   button[i].setBackground(new Color(58, 226, 206));
   p.add(button[i]);
   button[i].addActionListener(this);
  } //for

  this.add("North", result);
  this.add("Center", p);
  this.setTitle("Calculator");
  this.setBounds(600,300,200,200);
  this.setVisible(true);
  this.addWindowListener(this);
 }//init()
 
 public void windowActivated(WindowEvent e) { }
 public void windowClosed(WindowEvent e) { }
 public void windowClosing(WindowEvent e) {
  System.exit(0);
 }
 public void windowDeactivated(WindowEvent e) { }
 public void windowDeiconified(WindowEvent e) { }
 public void windowIconified(WindowEvent e) { }
 public void windowOpened(WindowEvent e) { }
 
 public void actionPerformed(ActionEvent e) {
  String in = e.getActionCommand();

  if(in.equals("C")){
   result.setText("0");
   num_state = true;
  }else if('0' <= in.charAt(0) && in.charAt(0) <= '9') {
   if (num_state)
    result.setText(in);
   else
    result.setText(result.getText() +in);
   num_state = false;
  }

   if(in.equals("/") || in.equals("*") || in.equals("-") || in.equals("+")) {
    num_temp = result.getText();
    op_temp = in;
    num_state=true;
   }else if(in.equals("=")) {
    if(operator_state) {
     double num1 = Double.parseDouble(num_temp);
     double num2 = Double.parseDouble(result.getText());

     if(op_temp.equals("+")) {
      result.setText("" + (num1+num2));
     }else if(op_temp.equals("-")) {
      result.setText("" + (num1-num2));
     }else if(op_temp.equals("*")) {
      result.setText("" + (num1*num2));
     }else if(op_temp.equals("/")) {
      result.setText("" + (num1/num2));
     }
    }
   }
 }

 public static void main(String[] args) {
  Calculator ct = new Calculator();
  ct.init();
  }
 }

Swing을 이용한 간단한 - 그림판 -

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.JCheckBox;
import javax.swing.JButton;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JComboBox;
import java.awt.FlowLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;

class GraphicTest extends JFrame implements ActionListener {
 JLabel x1L, y1L, x2L, y2L, z1L, z2L;
 JTextField x1T, y1T, x2T, y2T, z1T, z2T;
 JCheckBox fill;
 JRadioButton line, circle, rect, roundR, arc;
 JButton draw;
 DrCanvas can;
 JComboBox combo;

 int x1, y1, x2, y2, z1, z2;
 
 public GraphicTest() {
  super("간단 그림판");//setTitle("간단 그림판"); //super는 맨위쪽

  x1L = new JLabel("x1L");
  y1L = new JLabel("y1L");
  x2L = new JLabel("x2L");
  y2L = new JLabel("y2L");
  z1L = new JLabel("z1L");
  z2L = new JLabel("z2L");

  x1T = new JTextField("100",4);
  y1T = new JTextField("150",4);
  x2T = new JTextField("200",4);
  y2T = new JTextField("250",4);
  z1T = new JTextField("80",4);
  z2T = new JTextField("80",4);

  fill = new JCheckBox("채우기");

  line = new JRadioButton("선");
  circle = new JRadioButton("원");
  rect = new JRadioButton("사각형", true);
  roundR = new JRadioButton("둥근사각형");
  arc = new JRadioButton("호");

  ButtonGroup bg = new ButtonGroup();
  bg.add(line);
  bg.add(circle);
  bg.add(rect);
  bg.add(roundR);
  bg.add(arc);

  draw = new JButton("그리기");
 
  can = new DrCanvas();

  String[] color = {"빨강", "초록", "파랑", "검정", "보라"};
  combo = new JComboBox(color);

  JPanel p = new JPanel(); //FlowLayout(순서배치)    

  p.add(x1L); p.add(x1T);
  p.add(y1L); p.add(y1T);
  p.add(x2L); p.add(x2T);
  p.add(y2L); p.add(y2T);
  p.add(z1L); p.add(z1T);
  p.add(z2L); p.add(z2T);
  p.add(fill);  

  JPanel p2 = new JPanel();

  p2.add(line);
  p2.add(circle);
  p2.add(rect);
  p2.add(roundR);
  p2.add(arc);
  p2.add(combo);
  p2.add(draw);

  getContentPane().add("North", p);
  getContentPane().add("South", p2);
  getContentPane().add("Center", can);

  setBounds(500,100,600,500);
  setVisible(true);
  setDefaultCloseOperation(EXIT_ON_CLOSE);  

  //이벤트 처리
  draw.addActionListener(this);
  line.addActionListener(this);
  circle.addActionListener(this);
  rect.addActionListener(this);
  roundR.addActionListener(this);
  arc.addActionListener(this);    
  can.addMouseListener(new MouseAdapter() {
   public void mousePressed(MouseEvent e) {
    x1T.setText(String.valueOf(e.getX()));
    y1T.setText(String.valueOf(e.getY()));
    can.repaint();
   }
  });
  can.addMouseMotionListener(new MouseMotionAdapter(){
   public void mouseDragged(MouseEvent e){
    x2T.setText(String.valueOf(e.getX()));
    y2T.setText(String.valueOf(e.getY()));
    can.repaint();
   }
  });
 }//GraphicTest( )
 
 //ActionListner override
 public void actionPerformed(ActionEvent e){
   can.repaint(); //update () -> paint() 순서로 호출
 }

 class DrCanvas extends Canvas {
  public  DrCanvas() {
   this.setBackground(new Color(255,255,100)); //바탕색 -연한노랑
   setForeground(new Color(255,0,0));//글자색
  }//DrCanvas( )

  public void paint(Graphics g) {
   //좌표 얻어오기
   x1 = Integer.parseInt(x1T.getText().trim()); //trim - 앞뒤공백제거
   y1 = Integer.parseInt(y1T.getText().trim());
   x2 = Integer.parseInt(x2T.getText().trim());
   y2 = Integer.parseInt(y2T.getText().trim());
   z1 = Integer.parseInt(z1T.getText().trim());
   z2 = Integer.parseInt(z2T.getText().trim());    
   
   //색
   switch(combo.getSelectedIndex()) {
    case 0: this.setForeground(new Color (255,0,0));
     break;    
    case 1: this.setForeground(new Color (0,255,0));
     break;
    case 2: this.setForeground(new Color (0,0,255));
     break;
    case 3: this.setForeground(new Color (0,0,0));
     break;
    case 4: this.setForeground(new Color (255,0,255));
     break;
   }//switch

   int startX = x1 < x2 ? x1 : x2;
   int startY = y1 < y2 ? y1 : y2;
   int width = x1 < x2 ? x2-x1 : x1-x2;
   int height = y1 < y2 ? y2-y1 : y1-y2;

   //도형 그리기
   if(fill.isSelected()) {  //채우기 선택
    if(line.isSelected())
     g.drawLine(x1, y1, x2, y2);
    else if(circle.isSelected())
     g.fillOval(startX, startY, width, height);
    else if(rect.isSelected())
     g.fillRect(startX, startY, width, height);
    else if(roundR.isSelected())
     g.fillRoundRect(startX, startY, width, height, z1, z2);
    else if(arc.isSelected())
     g.fillArc(startX, startY, width, height, z1, z2);
   }else { //채우기 해제
    if(line.isSelected())
     g.drawLine(x1, y1, x2, y2);
    else if(circle.isSelected())
     g.drawOval(startX, startY, width, height);
    else if(rect.isSelected())
     g.drawRect(startX, startY, width, height);
    else if(roundR.isSelected())
     g.drawRoundRect(startX, startY, width, height, z1, z2);
    else if(arc.isSelected())
     g.drawArc(startX, startY, width, height, z1, z2);
   }//else  
  }//paint( )
 } //DrCanvas

 public static void main(String[] args) {
  new GraphicTest();  
 }//main( )
}

2009년 7월 12일 일요일

Yasu 야수 1.6.9040 released

 

 

Yasu 1.6버전이 릴리즈 되었습니다.

 

Version History:

Modified Y.A.S.U for exclusive use of DAEMON-Tools devices

(Please copy YASU.exe to your DAEMON-Tools directory).

 

Created for DAEMON Tools Lite v4.30.3 (or newer, will NOT work with older versions).
 
 Current version of Y.A.S.U v1.6.9040 was tested with DAEMON Tools Lite v4.30.3 &
 DAEMON Tools Pro v4.30.304.47 with SPTD 1.56.

 Run Y.A.S.U click "Cloak" to hide your devices, run your game without any hassles
 from the protection scheme (SecuROM/SafeDisc).
 To restore your settings simply click "Uncloak" and/or close/quit Y.A.S.U.

 

실행 방법 :

1.  Damon-Tools가 인스톨 된 디렉토리에 Yasu.exe파일을 복사합니다.

2. Yasu.exe파일을 실행합니다.

3. Cloak버튼을 누른다음 게임을 실행 하면 됩니다.

USB 메모리에 CD영역 만들기 - UCDExec

이 글은 Furyheimdall 에 의해 furyheimdall.tistory.com 에서 작성되었습니다.

 

USB 메모리에 CD 영역을 만들 수 있는 프로그램입니다.

USB 메모리 일부를 CD 영역으로 할당하는 방식인데 바이오스 상태에서도 USB CD-ROM 으로 인식하기

때문에 윈도우 설치본을 넣어두거나 다른 CD미디어 자체를 요구하는데 매우 요긴합니다.

프로그램 자체는 USB 메모리 특성을 꽤나 타기 때문에 만약 이 프로그램으로 되지 않는다면

USBOFFICE.KR 에서 찾아보시기 바랍니다

프로그램 사용법은 프로그램을 실행하시면 나오는 창에서 ISO File 을 지정해주고 Burn을 하면

자동으로 영역이 할당되면서 지정한 이미지 내용이 별도의 CD_ROM 으로 인식하게 됩니다.
주의하실점은 포맷하게 되기 때문에 굽기(?)전에 꼭 기존 내용을 백업하세요.

현재 지원되는 모델은 어떤게 있는지 모르겠습니다만 제 USB 메모리 Zyrus 스윙캡 8GB 모델의 경우 지원이 되더군요.  제 경우는 Office.kr 에서 MDPT 를 사용하라고 했지만 오히려 그게 제 메모리를 인식하지 못해서 다른 프로그램을 찾다가 이 프로그램을 발견하게 되었습니다.

이 프로그램을 실행했을때 장치를 못찾았다고 하면 그건 지원되지 않는 모델이기 때문에 다른 프로그램을 찾아보세요.