java 실습 0717

실습과제 모음 2012. 7. 17. 17:16 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import javax.swing.*;
 
import java.awt.*;
import java.awt.event.*;
 
class MyFrame extends JFrame implements MouseListener, MouseMotionListener {
 
       public MyFrame() {
             setTitle("Mouse Event");
             setSize(300, 200);
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
             JPanel panel = new JPanel();
             panel.addMouseListener(this);
             panel.addMouseMotionListener(this);
             add(panel);
             setVisible(true);
 
       }
       public void mousePressed(MouseEvent e) {
           display("Mouse pressed (# of clicks: " + e.getClickCount() + ")", e);
     }

     public void mouseReleased(MouseEvent e) {
           display("Mouse released (# of clicks: " + e.getClickCount() + ")", e);
     }

     public void mouseEntered(MouseEvent e) {
           display("Mouse entered", e);
     }

     public void mouseExited(MouseEvent e) {
           display("Mouse exited", e);
     }

     public void mouseClicked(MouseEvent e) {
           display("Mouse clicked (# of clicks: " + e.getClickCount() + ")", e);
     }
     protected void display(String s, MouseEvent e) {
         System.out.println(s + " X=" + e.getX() + " Y=" + e.getY());
   }

   public void mouseDragged(MouseEvent e) {
         display("Mouse dragged", e);
   }

   public void mouseMoved(MouseEvent e) {
         display("Mouse moved", e);
        
   }
}

public class MyFrameTest5 {
   public static void main(String[] args) {
         MyFrame f=new MyFrame();
   }
}

'실습과제 모음' 카테고리의 다른 글

JRadioButtonTest  (0) 2012.07.18
JCheckBoxTest  (0) 2012.07.18
JAVA ComboBoxTest  (0) 2012.07.14
CPP 실습문제 0714  (0) 2012.07.14
JAVA 0711 실습과제  (0) 2012.07.11

JAVA ComboBoxTest

실습과제 모음 2012. 7. 14. 15:54 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ComboBoxTest extends JFrame implements ActionListener {
 JLabel label;

 public ComboBoxTest() {
  setTitle("콤보 박스");
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setSize(300, 200);

  String[] animals = { "dog", "lion", "tiger" };
  JComboBox animalList = new JComboBox(animals);
  animalList.setSelectedIndex(0);
  animalList.addActionListener(this);

  label = new JLabel();
  label.setHorizontalAlignment(JLabel.CENTER);
  changePicture(animals[animalList.getSelectedIndex()]);
  add(animalList, BorderLayout.PAGE_START);
  add(label, BorderLayout.PAGE_END);
  setVisible(true);
 }

 public void actionPerformed(ActionEvent e) {
  JComboBox cb = (JComboBox) e.getSource();
  String name = (String) cb.getSelectedItem();
  changePicture(name);
 }

 protected void changePicture(String name) {
  ImageIcon icon = new ImageIcon(name + ".gif");
  label.setIcon(icon);
  if (icon != null) {
   label.setText(null);
  } else {
   label.setText("이미지가 발견되지 않았습니다.");
  }
 }

 public static void main(String[] args) {
  ComboBoxTest frame = new ComboBoxTest();
 }
}

 

 

 

 

'실습과제 모음' 카테고리의 다른 글

JCheckBoxTest  (0) 2012.07.18
java 실습 0717  (0) 2012.07.17
CPP 실습문제 0714  (0) 2012.07.14
JAVA 0711 실습과제  (0) 2012.07.11
C 언어 실습문제  (0) 2012.07.11

CPP 실습문제 0714

실습과제 모음 2012. 7. 14. 11:32 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <iostream>
using namespace std;

class Weight
{
public :
 void setHeight(const double h);
 void setWeight(const double h);
 double getHeight();
 double getWeight();
 int    getWeightStatus();

private :
 int    StdWeight();
 double height, weight;
 int    WeightStatus;
};


void Weight::setHeight(const double h)
{
}

void Weight::setWeight(const double w)
{
}

double Weight::getHeight()
{
}

double Weight::getWeight()
{
}

int Weight::StdWeight()
{
 double sw=(height-110)*0.9;

 if (sw+0.5 < weight)
  WeightStatus=1;
 else if (sw-0.5 > weight)
  WeightStatus=-1;
 else
  WeightStatus=0;

 return 1;
}

int Weight::getWeightStatus()
{
}

int main()
{
 Weight w1; 
 w1.setHeight(175);
 w1.setWeight(87.5);
 cout << w1.getHeight() << "키에 몸무게 ";
 cout << w1.getWeight() << "는 ";
 switch (w1.getWeightStatus())
 {
 case 1:
  cout << "과체중";
  break;
 case 0 :
  cout << "정상";
  break;
 case -1:
  cout << "저체중";
  break;
 default:
  ;
 }
 cout << " 입니다." << endl;

 return 0;
}

 

include.dotx

'실습과제 모음' 카테고리의 다른 글

JCheckBoxTest  (0) 2012.07.18
java 실습 0717  (0) 2012.07.17
JAVA ComboBoxTest  (0) 2012.07.14
JAVA 0711 실습과제  (0) 2012.07.11
C 언어 실습문제  (0) 2012.07.11

JAVA 0711 실습과제

실습과제 모음 2012. 7. 11. 18:33 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


  /*
  ex) 3입력시
    * 1
   *** 2
  ***** 3
   *** 2
    * 1
  */

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

  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  int i, j, k;

  System.out.print("입력 :");
  i = Integer.parseInt(in.readLine());
  
  System.out.println("i = " + i);
  
  // 위부분 출력
  for(k = 1; k <= i ; k++ )
  {
   for(j = 0; j < i - k; j++)
   {
    System.out.print(" ");
   }
   for(j = 0; j < 2*k-1; j++)
   {
    System.out.print("*");
   }
   System.out.print("\n");
  }
  
  
  // 아래부분 출력
  for(k = 1; k <= i ; k++ )
  {
   for(j = 0; j < i - k; j++)
   {
    System.out.print(" ");
   }
   for(j = 0; j < 2*k-1; j++)
   {
    System.out.print("*");
   }
   System.out.print("\n");
  }
  
  
  /*

  for (j = 0; j < i; j++) {
   System.out.print("*");
  }

  System.out.print("\n");

  for (j = 0; j < i; j++) {
   System.out.print("*");
   System.out.print("\n");
  }
  */

 }
}

'실습과제 모음' 카테고리의 다른 글

JCheckBoxTest  (0) 2012.07.18
java 실습 0717  (0) 2012.07.17
JAVA ComboBoxTest  (0) 2012.07.14
CPP 실습문제 0714  (0) 2012.07.14
C 언어 실습문제  (0) 2012.07.11

C 언어 실습문제

실습과제 모음 2012. 7. 11. 15:09 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

C 언어 실습문제

 

문제 

세자리 정수를 입력받아 각 자리수를 출력하고 각 자리수가 짝수인지 홀수인지 출력하시오.

코드

#include <stdio.h>

int main(void)

{

   int num;

 

   printf("세자리 정수를 입력하세요 : ");

 

   scanf("%d", &num);

 

   printf("일의 자리수 : %d \n", num % 10);

 

   printf("십의 자리수 : %d \n", num / 10 % 10);

 

   printf("백의 자리수 : %d \n", num / 100);

 

   if( (num % 10) % 2 == 0 )

   {

       printf("일의 자리수는 짝수\n");

   }

   else

   {

       printf("일의 자리수는 홀수\n");

   }

 

   if( (num / 10 % 10) % 2 == 0 )

   {

       printf("십의 자리수는 짝수\n");

   }

   else

   {

       printf("십의 자리수는 홀수\n");

   }

 

   if( (num / 100) % 2 == 0 )

   {

       printf("백의 자리수는 짝수\n");

   }

   else

   {

       printf("백의 자리수는 홀수\n");

   }

 

   return 0;

}

 

 

'실습과제 모음' 카테고리의 다른 글

JCheckBoxTest  (0) 2012.07.18
java 실습 0717  (0) 2012.07.17
JAVA ComboBoxTest  (0) 2012.07.14
CPP 실습문제 0714  (0) 2012.07.14
JAVA 0711 실습과제  (0) 2012.07.11