Search

'소스코드'에 해당되는 글 5건

  1. 2014.07.12 Java Chatting Server, Client
  2. 2014.07.12 JAVA 채팅 소스 -1 Client 쪽
  3. 2013.12.22 JAVA GUI 계산기 소스코드
  4. 2012.07.23 C 달력 소스코드 2
  5. 2012.07.21 CPP 달력 소스코드

Java Chatting Server, Client

Programming/JAVA,JSP 2014. 7. 12. 16:18 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

 

 

 

 

JavaChattingClient.zip

 

JavaChattingServer.zip

 

'Programming > JAVA,JSP' 카테고리의 다른 글

mysql table datetime tip  (0) 2014.10.20
JSP, MYSQL, ECLIPSE 연동하기  (0) 2014.10.12
JScrollPane , ScrollPane 차이점  (0) 2014.07.12
Java ScrollPane 활용  (0) 2014.07.12
java  (0) 2014.07.12

JAVA 채팅 소스 -1 Client 쪽

Programming/JAVA,JSP 2014. 7. 12. 14:50 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.PrintWriter;

import java.net.Socket;

import java.net.UnknownHostException;

import java.util.Scanner;

 

class RecvThread extends Thread {

     Socket s;

 

     public RecvThread(Socket s) {

          this.s = s;

     }

 

     @Override

     public void run() {

          // 받는 부분

          BufferedReader is;

          try {

              is = new BufferedReader(new InputStreamReader(s.getInputStream()));

              String recvMsg;

              while ((recvMsg = is.readLine()) != null) {

                   System.out.println(recvMsg);

              }

          } catch (IOException e) {

              // TODO Auto-generated catch block

              e.printStackTrace();

          }

     }

}

 

class SendThread extends Thread {

     Socket s;

 

     public SendThread(Socket s) {

          this.s = s;

     }

 

     @Override

     public void run() {

          PrintWriter os;

          try {

              os = new PrintWriter(s.getOutputStream(), true);

              // 보내는 부분

              Scanner sc = new Scanner(System.in);

              while (true) {

                   String msg = sc.next();

                   os.println(msg);

              }

          } catch (IOException e) {

              // TODO Auto-generated catch block

              e.printStackTrace();

          }

     }

 

}

 

public class ClientTest {

     public static void main(String[] args) {

          try {

              Socket s = new Socket("115.20.247.142", 4000);

              SendThread st = new SendThread(s);

              RecvThread rt = new RecvThread(s);

          } catch (UnknownHostException e) {

              // TODO Auto-generated catch block

              e.printStackTrace();

          } catch (IOException e) {

              // TODO Auto-generated catch block

              e.printStackTrace();

          }

     }

}

 

 

'Programming > JAVA,JSP' 카테고리의 다른 글

Java ScrollPane 활용  (0) 2014.07.12
java  (0) 2014.07.12
Java 선택 정렬 알고리즘 구현  (0) 2014.06.14
String to int, int to String  (0) 2014.06.07
이클립스 라인넘버 표시  (1) 2014.03.07

JAVA GUI 계산기 소스코드

Programming/JAVA,JSP 2013. 12. 22. 17:55 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;


import javax.swing.JButton;


/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */


/**

 * 

 * @author Administrator

 */

public class NewJFrame extends javax.swing.JFrame implements ActionListener {


/**

* Creates new form NewJFrame

*/

public NewJFrame() {

initComponents();

toDo();

}


private void toDo() {

// TODO Auto-generated method stub

jButton2.addActionListener(this);

jButton3.addActionListener(this);

jButton4.addActionListener(this);

jButton5.addActionListener(this);

jButton6.addActionListener(this);

jButton7.addActionListener(this);

jButton8.addActionListener(this);

jButton9.addActionListener(this);

jButton10.addActionListener(this);

jButton13.addActionListener(this);

jButton14.addActionListener(this);

jButton15.addActionListener(this);

jButton16.addActionListener(this);

jButton17.addActionListener(this);

jButton18.addActionListener(this);

}


@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {


jButton2 = new javax.swing.JButton();

jTextField3 = new javax.swing.JTextField();

jButton3 = new javax.swing.JButton();

jButton4 = new javax.swing.JButton();

jButton7 = new javax.swing.JButton();

jButton5 = new javax.swing.JButton();

jButton6 = new javax.swing.JButton();

jButton8 = new javax.swing.JButton();

jButton9 = new javax.swing.JButton();

jButton10 = new javax.swing.JButton();

jButton13 = new javax.swing.JButton();

jButton14 = new javax.swing.JButton();

jButton15 = new javax.swing.JButton();

jButton16 = new javax.swing.JButton();

jButton17 = new javax.swing.JButton();

jButton18 = new javax.swing.JButton();

jToggleButton1 = new javax.swing.JToggleButton();


setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);


jTextField3.setText("");


jButton2.setText("1");


jButton3.setText("2");


jButton4.setText("3");


jButton5.setText("4");


jButton6.setText("5");


jButton7.setText("6");


jButton8.setText("7");


jButton9.setText("8");


jButton10.setText("9");


jButton13.setText("0");


jButton14.setText("+");


jButton15.setText("/");


jButton16.setText("x");


jButton17.setText("-");


jButton18.setText("=");


jToggleButton1.setText("jToggleButton1");


javax.swing.GroupLayout layout = new javax.swing.GroupLayout(

getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(layout

.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jTextField3)

.addGroup(

layout.createSequentialGroup()

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.TRAILING)

.addGroup(

layout.createSequentialGroup()

.addComponent(

jButton5)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton6)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton7))

.addGroup(

layout.createSequentialGroup()

.addComponent(

jButton2)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton3)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton4)))

.addGroup(

layout.createSequentialGroup()

.addComponent(

jButton9)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(

jButton13)

.addGroup(

layout.createSequentialGroup()

.addComponent(

jButton10)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton8)))))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(

layout.createSequentialGroup()

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(

jButton16)

.addComponent(

jButton15))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton18))

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.TRAILING)

.addComponent(

jButton17)

.addComponent(

jButton14)))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED,

javax.swing.GroupLayout.DEFAULT_SIZE,

Short.MAX_VALUE)

.addComponent(jToggleButton1,

javax.swing.GroupLayout.PREFERRED_SIZE,

70,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap()));

layout.setVerticalGroup(layout

.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(

layout.createSequentialGroup()

.addComponent(jTextField3,

javax.swing.GroupLayout.PREFERRED_SIZE,

70,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.LEADING,

false)

.addGroup(

layout.createSequentialGroup()

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(

jButton2)

.addComponent(

jButton3)

.addComponent(

jButton4))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(

jButton5)

.addComponent(

jButton6)

.addComponent(

jButton7))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(

jButton9)

.addComponent(

jButton10)

.addComponent(

jButton8))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton13))

.addGroup(

layout.createSequentialGroup()

.addComponent(

jButton14)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton17)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton16)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton15))

.addComponent(

jButton18,

javax.swing.GroupLayout.DEFAULT_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE,

Short.MAX_VALUE)

.addComponent(

jToggleButton1,

javax.swing.GroupLayout.DEFAULT_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE,

Short.MAX_VALUE))

.addContainerGap(

javax.swing.GroupLayout.DEFAULT_SIZE,

Short.MAX_VALUE)));


pack();

}// </editor-fold>


public static void main(String args[]) {

/* Set the Nimbus look and feel */

// <editor-fold defaultstate="collapsed"

// desc=" Look and feel setting code (optional) ">

/*

* If Nimbus (introduced in Java SE 6) is not available, stay with the

* default look and feel. For details see

* http://download.oracle.com/javase

* /tutorial/uiswing/lookandfeel/plaf.html

*/

try {

for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager

.getInstalledLookAndFeels()) {

if ("Nimbus".equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName());

break;

}

}

} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

java.util.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

java.util.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

java.util.logging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

java.util.logging.Level.SEVERE, null, ex);

}

// </editor-fold>


/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new NewJFrame().setVisible(true);

}

});

}


// Variables declaration - do not modify

private javax.swing.JButton jButton10;

private javax.swing.JButton jButton13;

private javax.swing.JButton jButton14;

private javax.swing.JButton jButton15;

private javax.swing.JButton jButton16;

private javax.swing.JButton jButton17;

private javax.swing.JButton jButton18;

private javax.swing.JButton jButton2;

private javax.swing.JButton jButton3;

private javax.swing.JButton jButton4;

private javax.swing.JButton jButton7;

private javax.swing.JButton jButton5;

private javax.swing.JButton jButton6;

private javax.swing.JButton jButton8;

private javax.swing.JButton jButton9;

private javax.swing.JTextField jTextField3;

private javax.swing.JToggleButton jToggleButton1;


// End of variables declaration

@Override

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

if (arg0.getSource() == jButton2) {

jTextField3.setText(jTextField3.getText() + 1);

} else if (arg0.getSource() == jButton3) {

jTextField3.setText(jTextField3.getText() + "2");

} else if (arg0.getSource() == jButton4) {

jTextField3.setText(jTextField3.getText() + "3");

} else if (arg0.getSource() == jButton7) {

jTextField3.setText(jTextField3.getText() + "4");

} else if (arg0.getSource() == jButton5) {

jTextField3.setText(jTextField3.getText() + "5");

} else if (arg0.getSource() == jButton6) {

jTextField3.setText(jTextField3.getText() + "6");

} else if (arg0.getSource() == jButton8) {

jTextField3.setText(jTextField3.getText() + "7");

} else if (arg0.getSource() == jButton9) {

jTextField3.setText(jTextField3.getText() + "8");

} else if (arg0.getSource() == jButton10) {

jTextField3.setText(jTextField3.getText() + "9");

} else if (arg0.getSource() == jButton13) {

jTextField3.setText(jTextField3.getText() + "0");

} else if (arg0.getSource() == jButton14) {// +

tempValue = Integer.parseInt(jTextField3.getText());

operator = '+';

jTextField3.setText("");

} else if (arg0.getSource() == jButton15) {// /

tempValue = Integer.parseInt(

jTextField3.getText());

operator = '/';

jTextField3.setText("");

} else if (arg0.getSource() == jButton16) {// x

tempValue = Integer.parseInt(jTextField3.getText());

operator = '*';

jTextField3.setText("");

} else if (arg0.getSource() == jButton17) {// -

tempValue = Integer.parseInt(jTextField3.getText());

operator = '-';

jTextField3.setText("");

} else if (arg0.getSource() == jButton18) {// -

int tempValue2 = Integer.parseInt(

jTextField3.getText());

int resultValue = 0;

if (operator == '+') {

resultValue = tempValue + tempValue2;

} else if (operator == '-') {

resultValue = tempValue - tempValue2;

} else if (operator == '*') {

resultValue = tempValue * tempValue2;

} else if (operator == '/') {

resultValue = tempValue / tempValue2;

}

jTextField3.setText("" + resultValue);

}

}


int tempValue;

char operator;

}



'Programming > JAVA,JSP' 카테고리의 다른 글

Calendar #1  (0) 2013.12.31
JAVA 파일 검색 코드  (0) 2013.12.28
JAVA 소수를 구하는 프로그램 GUI #2  (0) 2013.12.21
JAVA 소수를 판단하는 GUI 프로그램  (0) 2013.12.21
JAVA 버블 정렬  (0) 2013.11.30

C 달력 소스코드

Programming/C,CPP,CS 2012. 7. 23. 04:30 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <stdio.h>

#include <windows.h>   // 콘솔색상을바꾸기위해서선언

 

#define leapyear(year) ((year)%4==0 && ( (year)%100!=0 || (year)%400==0 )) //윤년판정매크로

 

// Console 글씨색상을바꾸는함수

void SetConsoleTextColor(int bgcolor , int color);

 

int main(void)

{

    int year, month=0;

    int totalday[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

    int lastyear, day, i;

    FILE * fp = fopen("output5.txt", "wt"); //output5.txt에출력하기위해오픈한다.

 

    printf("몇년의달력을출력하시겠습니까?: ");

    scanf("%d",&year);

    printf("몇월의달력을출력하시겠습니까?: ");

    scanf("%d",&month);

    if(month==2 && leapyear(year))  totalday[2]=29;

    lastyear = year-1;

    {

        day = (lastyear+(lastyear/4)-(lastyear/100)+(lastyear/400)+1)%7;

        for(i=1;i < month;i++)

        {

            day+=totalday[i];

            day%=7;

        }

        // console에출력

        printf("\n           ");

        SetConsoleTextColor(0x0 , 0xe);              // 노란색글씨로바꾼다.

        printf("%d%d\n",year,month);

        SetConsoleTextColor(0x0 , 0xc);              // 빨간색글씨로바꾼다.

        printf("\n  ");

        SetConsoleTextColor(0x0 , 0xf);              // 흰색글씨로복귀

        printf("월화수목금");

        SetConsoleTextColor(0x0 , 0x9);              // 파란색글씨로바꾼다.

        printf("  ");

        SetConsoleTextColor(0x0 , 0xf);              // 흰색글씨로복귀

 

        // 파일에출력

        fprintf(fp, "\n           %d%d\n",year,month);

        fprintf(fp, "\n  일월화수목금토");

 

        for(i=-day; i<totalday[month]; i++)

        {

            if((i+day)%7 == 0)

            {

                printf("\n");

                fprintf(fp, "\n");

            }

            if(i<0)

            {

                printf("    ");

                fprintf(fp, "    ");

            }

            else

            {

                // 토요일일경우에는파란색으로출력한다

                if( (i+day)%7 == 6)   SetConsoleTextColor(0x0 , 0x9);

                // 일요일일경우에는빨간색으로출력한다.

                if( (i+day)%7 == 0)   SetConsoleTextColor(0x0 , 0xc);printf("%4d",i+1);

                // 원래흰색글씨로복귀시킨다.

                SetConsoleTextColor(0x0 , 0xf);

                fprintf(fp, "%4d",i+1);

            }

        }

    }

    printf("\n\n");

    fprintf(fp, "\n\n");

    fclose(fp);

    return 0;

}

 

 

// Console 글씨색상을바꾸는함수

void SetConsoleTextColor(int bgcolor , int color)

{

    bgcolor &= 0xf;

    color      &= 0xf;

    SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE) , (bgcolor << 4) | color );

}

 

 

 

'Programming > C,CPP,CS' 카테고리의 다른 글

프로그래밍 경진대회 관련 사이트  (0) 2012.10.14
CPP 예외처리  (0) 2012.09.23
C언어 정렬 알고리즘 예제  (0) 2012.08.26
CPP 달력 소스코드  (0) 2012.07.21
정렬 알고리즘 정리  (0) 2012.07.20

CPP 달력 소스코드

Programming/C,CPP,CS 2012. 7. 21. 10:30 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <iostream>
using namespace std;


int main()
{
 int year;
 int month;
 int totalDay = 0;
 int i = 1990;
 int dayOfWeek; // 0 : 월, 1: 화, .....
 int dayOfMonth; // 해당 달의 총 일수

 cout << "년도 입력 : " ;
 cin >> year;
 cout << "월 입력 : " ;
 cin >> month;

 for( ; i < year ; i++)
 {
  if( i % 4 == 0 && i % 100 != 0 || i % 400 == 0 )
  {
   totalDay += 366;
  }
  else
  {
   totalDay += 365;
  }
 }

 cout << year << "년 1월 1일 까지의 일수 " << totalDay << "요일 : ";

 switch( totalDay % 7 )
 {
 case 0:
  cout << "월요일" << endl;
  break;
 case 1:
  cout << "화요일" << endl;
  break;
 case 2:
  cout << "수요일" << endl;
  break;
 case 3:
  cout << "목요일" << endl;
  break;
 case 4:
  cout << "금요일" << endl;
  break;
 case 5:
  cout << "토요일" << endl;
  break;
 case 6:
  cout << "일요일" << endl;
  break;
 }

 for( i = 1; i < month ; i++ ) // 5
 {
  // 1 + 2 + 3 + 4
  switch(i)
  {
  case 1:
  case 3:
  case 5:
  case 7:
  case 8:
  case 10:
  case 12:
   totalDay += 31;
   break;
  case 4:
  case 6:
  case 9:
  case 11:
   totalDay += 30;
   break;
  case 2:
   if( (year % 4) == 0 && ( (year % 100) != 0 || (year % 400) == 0 ) )
   {
    totalDay += 29;
   }
   else
   {
    totalDay += 28;
   }
   break;
  }
 }

 cout << year << "년 "<< month<<"월 1일 까지의 일수 " << totalDay << "요일 : ";

 switch( totalDay % 7 )
 {
 case 0:
  cout << "월요일" << endl;
  break;
 case 1:
  cout << "화요일" << endl;
  break;
 case 2:
  cout << "수요일" << endl;
  break;
 case 3:
  cout << "목요일" << endl;
  break;
 case 4:
  cout << "금요일" << endl;
  break;
 case 5:
  cout << "토요일" << endl;
  break;
 case 6:
  cout << "일요일" << endl;
  break;
 } 


 switch(month)
 {
 case 1:
 case 3:
 case 5:
 case 7:
 case 8:
 case 10:
 case 12:
  dayOfMonth = 31;
  break;
 case 4:
 case 6:
 case 9:
 case 11:
  dayOfMonth = 30;
  break;
 case 2:
  if( (year % 4) == 0 && ( (year % 100) != 0 || (year % 400) == 0 ) )
  {
   dayOfMonth = 29;
  }
  else
  {
   dayOfMonth = 28;
  }
  break;
 }

 cout << year << "년 " << month << "월 달력 =====" << endl;
 cout << "월 화 수 목 금 토 일" << endl;
 cout << dayOfMonth << "일 입니다" << endl;

 

 for( i = 0 ; i < totalDay % 7 ; i++)
 {
  cout << "   " ;
 }
 for(i = 1; i <= dayOfMonth ; i ++ )
 {  
  printf("%2d ", i);

  if( totalDay % 7 == 6)
  {
   cout << endl;
  }
  totalDay++;  
 }


 cout << endl << endl;


 return 0;
}

 

'Programming > C,CPP,CS' 카테고리의 다른 글

프로그래밍 경진대회 관련 사이트  (0) 2012.10.14
CPP 예외처리  (0) 2012.09.23
C언어 정렬 알고리즘 예제  (0) 2012.08.26
C 달력 소스코드  (2) 2012.07.23
정렬 알고리즘 정리  (0) 2012.07.20