Search

'Programming/JAVA,JSP'에 해당되는 글 97건

  1. 2012.11.17 JAVA 다중 계산 계산기
  2. 2012.11.17 JAVA TCP 통신 예제
  3. 2012.11.17 Java 계산기 레이아웃
  4. 2012.11.04 setLookAndFeel 예제
  5. 2012.11.04 JAVA Look and Feel 활용 사이트
  6. 2012.07.26 JAVA Applet Chatting Client
  7. 2012.07.25 Java 채팅 코드

JAVA 다중 계산 계산기

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

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;


import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTextField;


class Cal extends JFrame {


private JTextField t1;


private JButton b1, b2, b3, b4, b5, b6, b7, b8, b9, b0;


JButton pl, mi, mu, di, cal, c;


String x, y;


int operator;


// + - * /

// 0 1 2 3


public Cal() {


operator = 4;


setSize(285, 350);


setDefaultCloseOperation(EXIT_ON_CLOSE);


setTitle("Calculator");


JPanel p = new JPanel();


p.setLayout(null);


t1 = new JTextField(10);


p.add(t1);


b1 = new JButton("1");


p.add(b1);


b1.addActionListener(new Number());


b2 = new JButton("2");


p.add(b2);


b2.addActionListener(new Number());


b3 = new JButton("3");


p.add(b3);


b3.addActionListener(new Number());


b4 = new JButton("4");


p.add(b4);


b4.addActionListener(new Number());


b5 = new JButton("5");


p.add(b5);


b5.addActionListener(new Number());


b6 = new JButton("6");


p.add(b6);


b6.addActionListener(new Number());


b7 = new JButton("7");


p.add(b7);


b7.addActionListener(new Number());


b8 = new JButton("8");


p.add(b8);


b8.addActionListener(new Number());


b9 = new JButton("9");


p.add(b9);


b9.addActionListener(new Number());


b0 = new JButton("0");


p.add(b0);


b0.addActionListener(new Number());


pl = new JButton("+");


p.add(pl);


pl.addActionListener(new Number());


mi = new JButton("-");


p.add(mi);


mi.addActionListener(new Number());


mu = new JButton("*");


p.add(mu);


mu.addActionListener(new Number());


di = new JButton("/");


p.add(di);


di.addActionListener(new Number());


cal = new JButton("=");


p.add(cal);


cal.addActionListener(new Number());


c = new JButton("C");


p.add(c);


c.addActionListener(new Number());


t1.setBounds(10, 10, 245, 80);


b1.setBounds(10, 105, 45, 45);


b2.setBounds(60, 105, 45, 45);


b3.setBounds(110, 105, 45, 45);


b4.setBounds(10, 155, 45, 45);


b5.setBounds(60, 155, 45, 45);


b6.setBounds(110, 155, 45, 45);


b7.setBounds(10, 205, 45, 45);


b8.setBounds(60, 205, 45, 45);


b9.setBounds(110, 205, 45, 45);


b0.setBounds(60, 255, 45, 45);


pl.setBounds(160, 105, 45, 45);


mi.setBounds(160, 155, 45, 45);


mu.setBounds(160, 205, 45, 45);


di.setBounds(160, 255, 45, 45);


c.setBounds(110, 255, 45, 45);


cal.setBounds(210, 105, 45, 195);


add(p);


setVisible(true);


}


private class Number implements ActionListener {


public void actionPerformed(ActionEvent e) {


if (e.getSource() == b1) {

t1.setText(t1.getText() + "1");

} else if (e.getSource() == b2) {

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

} else if (e.getSource() == b3) {

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

} else if (e.getSource() == b4) {

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

} else if (e.getSource() == b5) {

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

} else if (e.getSource() == b6) {

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

} else if (e.getSource() == b7) {

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

} else if (e.getSource() == b8) {

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

} else if (e.getSource() == b9) {

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

} else if (e.getSource() == b0) {

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

} else if (e.getSource() == c) {

t1.setText("");

}

// + - * / x

// 0 1 2 3 4

else if (e.getSource() == pl) {

if (operator == 4) {

x = t1.getText();

t1.setText("");

operator = 0;

} else {

process();

x = "" + valX;

t1.setText("");

operator = 0;

}

} else if (e.getSource() == mi) {

if (operator == 4) {

x = t1.getText();

t1.setText("");

operator = 1;

} else {

process();

x = "" + valX;

t1.setText("");

operator = 1;

}

} else if (e.getSource() == mu) {

if (operator == 4) {

x = t1.getText();

t1.setText("");

operator = 2;

} else {

process();

x = "" + valX;

t1.setText("");

operator = 2;

}

} else if (e.getSource() == di) {

if (operator == 4) {

x = t1.getText();

t1.setText("");

operator = 3;

} else {

process();

x = "" + valX;

t1.setText("");

operator = 3;

}

} else if (e.getSource() == cal) {

process();

t1.setText("" + valX);

}

}


int valX;

int valY;


public void process() {

y = t1.getText();


valX = Integer.parseInt(x);

valY = Integer.parseInt(y);

switch (operator) {

case 0:

valX = valX + valY;

break;

case 1:

valX = valX - valY;

break;

case 2:

valX = valX * valY;

break;

case 3:

valX = valX / valY;

break;

}


operator = 4;

}


}


}


public class cals {


public static void main(String[] args) {


Cal Cals = new Cal();


}


}

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

JAVA 오목 게임 #1  (0) 2012.11.23
JAVA 프레임 안에 프레임  (1) 2012.11.18
JAVA TCP 통신 예제  (0) 2012.11.17
Java 계산기 레이아웃  (0) 2012.11.17
setLookAndFeel 예제  (0) 2012.11.04

JAVA TCP 통신 예제

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


EchoServer.java

package socket.echo;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.net.ServerSocket;    //ServerSocket 클래스는 TCP서버소켓을 의미한다.
import java.net.Socket;


public class EchoServer {

 private BufferedReader bufferR;
 private BufferedWriter bufferW;
 private InputStream is;
 private OutputStream os;
 private ServerSocket serverS;

 
 public EchoServer(int port){
  
  try{
   //ServerSocket 객체를 3000번 포트를 이용하여 생성.
   serverS = new ServerSocket(port);
  }catch(IOException ioe){
   ioe.printStackTrace();
   System.exit(0);
  }
 
  while(true){
    
    try{
       System.out.println("클라이언트의 요청을 기다리는 중");
    
//accept() 메서드를 이용하여 클라이언트의 TCP커넥션(클라이언트에서 Socket객체를 생성하는 것)을 기다리고 있다.
//accept() 메서드는 클라이언트의 Socket객체가 생성될 때까지 블로킹 되고 있다가 클라이언트의 Socket객체가 생성되면 서버에서 클라이언트와 통신할 수 있는 Socket 객체를 리턴하게 된다.
//accept() 메서드의 유효시간이 지나면 java.net.SocketTimeoutException이 발생하는데, 이 예외가 발생하더라도 ServerSocket객체는 계속 유효하다.
//실험결과 accept() 메서드가 Socket 객체를 리턴하지 않는 한 while문의 루프도 돌아가지 않았다.
    Socket tcpSocket = serverS.accept();
    System.out.println("클라이언트의 IP주소 : "+tcpSocket.getInetAddress().getHostAddress());
    is = tcpSocket.getInputStream();     //'소켓으로부터' 읽고
    os = tcpSocket.getOutputStream();  //'소켓에' 쓴다.
    bufferR = new BufferedReader(new InputStreamReader(is));
    bufferW = new BufferedWriter(new OutputStreamWriter(os));
    String message = bufferR.readLine();
    System.out.println("수신메시지 : "+message);
    message += System.getProperty("line.separator");  //엔터키넣기
    bufferW.write(message);
    bufferW.flush();
    bufferR.close();
    bufferW.close();
    tcpSocket.close();
    
   }catch(IOException ie){
    ie.printStackTrace();
   }
   
  }
 
 }
 
 
 public static void main(String[] args){
    new EchoServer(3000);
 }
  
}





EchoClient.java

package socket.echo;

import java.io.*;
import java.net.*;

public class EchoClient {

 private String ip;
 private int port;
 private String str;
 BufferedReader file;
 
//생성자
 public EchoClient(String ip, int port) throws IOException{
  
  this.ip = ip;
  this.port = port;
//Socket객체를 생성한다. Socket객체가 생성되면 서버와 TCP 커넥션이 이루어지게 된다. 동시에 서버의 accept()메서드는 클라이언트와 통신할 수 있는 Socket객체를 반환하게 된다. 따라서 클라이언트의 Socket객체와 서버의 Socket객체가 각각의 스트림을 이용하여 통신할 수 있게 된다.
  Socket tcpSocket = getSocket();   //사용자 메서드
  OutputStream os_socket = tcpSocket.getOutputStream();   //소켓에 쓰고
  InputStream is_socket = tcpSocket.getInputStream();   //소켓에서 읽는다
  
  BufferedWriter bufferW = new BufferedWriter(new OutputStreamWriter(os_socket));
  BufferedReader bufferR = new BufferedReader(new InputStreamReader(is_socket));
  System.out.print("입력 : ");
  
//소켓으로부터 읽는 것이 아니라 키보드로부터 읽는 또 하나의 BufferedReader
  file = new BufferedReader(new InputStreamReader(System.in));
  str = file.readLine();
  str += System.getProperty("line.separator");
  bufferW.write(str);
  bufferW.flush();
  str = bufferR.readLine();
  System.out.println("Echo Result : "+str);
  
  file.close();
  bufferW.close();
  bufferR.close();
  tcpSocket.close();
  
 }
 
 
 public Socket getSocket(){   //호스트의 주소와 포트를 사용, 소켓을 만들어 리턴하는 사용자 메서드
  
  Socket tcpSocket = null;
  
  try{
//원격 호스트(여기서는 서버)의 주소와 포트(여기서는 멤버변수)를 사용하여 Socket객체를 생성한다.
//호스트를 찾을 수 없거나, 서버의 포트가 열려 있지 않은 경우에는 UnknownHostException 이 발생하고,
//네트워크의 실패, 또는 방화벽 때문에 서버에 접근할 수 없을 때에는 IOException 이 발생할 수 있다.

   tcpSocket = new Socket(ip, port);
  }catch(IOException ioe){
   ioe.printStackTrace();
   System.exit(0);
  }
  return tcpSocket;
  
 }
 

 public static void main(String[] args)throws IOException{
    new EchoClient("localhost", 3000);
 }
 
}

출처 : http://u2m.kr/77

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

JAVA 프레임 안에 프레임  (1) 2012.11.18
JAVA 다중 계산 계산기  (0) 2012.11.17
Java 계산기 레이아웃  (0) 2012.11.17
setLookAndFeel 예제  (0) 2012.11.04
JAVA Look and Feel 활용 사이트  (0) 2012.11.04

Java 계산기 레이아웃

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

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;


import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTextField;


class Cal extends JFrame {

private JTextField t1;

private JButton b1, b2, b3, b4, b5, b6, b7, b8, b9, b0;

JButton pl, mi, mu, di, cal, c;

String x, y;


public Cal() {

setSize(285, 350);

setDefaultCloseOperation(EXIT_ON_CLOSE);

setTitle("Calculator");

JPanel p = new JPanel();

p.setLayout(null);


t1 = new JTextField(10);

p.add(t1);


b1 = new JButton("1");

p.add(b1);

b1.addActionListener(new Number());


b2 = new JButton("2");

p.add(b2);

b2.addActionListener(new Number());


b3 = new JButton("3");

p.add(b3);

b3.addActionListener(new Number());


b4 = new JButton("4");

p.add(b4);

b4.addActionListener(new Number());


b5 = new JButton("5");

p.add(b5);

b5.addActionListener(new Number());


b6 = new JButton("6");

p.add(b6);

b6.addActionListener(new Number());


b7 = new JButton("7");

p.add(b7);

b7.addActionListener(new Number());


b8 = new JButton("8");

p.add(b8);

b8.addActionListener(new Number());


b9 = new JButton("9");

p.add(b9);

b9.addActionListener(new Number());


b0 = new JButton("0");

p.add(b0);

b0.addActionListener(new Number());


pl = new JButton("+");

p.add(pl);

pl.addActionListener(new Number());


mi = new JButton("-");

p.add(mi);

mi.addActionListener(new Number());


mu = new JButton("*");

p.add(mu);

mu.addActionListener(new Number());


di = new JButton("/");

p.add(di);

di.addActionListener(new Number());


cal = new JButton("=");

p.add(cal);

cal.addActionListener(new Number());


c = new JButton("C");

p.add(c);

c.addActionListener(new Number());


t1.setBounds(10, 10, 245, 80);

b1.setBounds(10, 105, 45, 45);

b2.setBounds(60, 105, 45, 45);

b3.setBounds(110, 105, 45, 45);

b4.setBounds(10, 155, 45, 45);

b5.setBounds(60, 155, 45, 45);

b6.setBounds(110, 155, 45, 45);

b7.setBounds(10, 205, 45, 45);

b8.setBounds(60, 205, 45, 45);

b9.setBounds(110, 205, 45, 45);

b0.setBounds(60, 255, 45, 45);

pl.setBounds(160, 105, 45, 45);

mi.setBounds(160, 155, 45, 45);

mu.setBounds(160, 205, 45, 45);

di.setBounds(160, 255, 45, 45);

c.setBounds(110, 255, 45, 45);

cal.setBounds(210, 105, 45, 195);


add(p);

setVisible(true);

}


private class Number implements ActionListener {

public void actionPerformed(ActionEvent e) {

}

}

}


public class cals {

public static void main(String[] args) {

Cal Cals = new Cal();


}

}

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

JAVA 다중 계산 계산기  (0) 2012.11.17
JAVA TCP 통신 예제  (0) 2012.11.17
setLookAndFeel 예제  (0) 2012.11.04
JAVA Look and Feel 활용 사이트  (0) 2012.11.04
JAVA Applet Chatting Client  (0) 2012.07.26

setLookAndFeel 예제

Programming/JAVA,JSP 2012. 11. 4. 13:54 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package com.kuro;


import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.SwingUtilities;

import javax.swing.UIManager;

import javax.swing.UnsupportedLookAndFeelException;


public class MyFrame extends JFrame {

public MyFrame() {

// TODO Auto-generated constructor stub


JButton button = new JButton("Hello");

JPanel panel = new JPanel();

panel.add(button);

add(panel);

try {

UIManager

.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");

SwingUtilities.updateComponentTreeUI(this);


} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (InstantiationException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalAccessException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (UnsupportedLookAndFeelException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

setSize(600, 400);

setVisible(true);

}


public static void main(String[] args) {

MyFrame mf = new MyFrame();

}

}


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

JAVA TCP 통신 예제  (0) 2012.11.17
Java 계산기 레이아웃  (0) 2012.11.17
JAVA Look and Feel 활용 사이트  (0) 2012.11.04
JAVA Applet Chatting Client  (0) 2012.07.26
Java 채팅 코드  (0) 2012.07.25

JAVA Look and Feel 활용 사이트

Programming/JAVA,JSP 2012. 11. 4. 10:05 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

http://geeknizer.com/best-java-swing-look-and-feel-themes-professional-casual-top-10/

http://dock.javaforge.com/ 



The Look and Feel Libraries are broadly divided into two categories.

  1. Skinnable
  2. Non-Skinnable

Skinnable look and feel can’t only change the LAF of wigets in your application, but, can also change the look and feel of window title bars and borders. So here are few Professional and Casual themes that you can use to make your application much more attractive and vibrant:

Professional Themes

Nimbus

This is the theme that’s getting a lot of popularity, specially, after Solaris 10 adopted it.

Here’s how you can set it:

UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");

Here’s a screenshot:

Substance
Substance has 6 different flavours for the metallic Look an Feel. The Good one is below. You can checkout other color schemes here (though they are not that attractive). Download

Sea Glass 
This is relatively anew theme under development. This one is among the best I’ve seen around. It that mocks Mac-kind look inspired by different colored stones. You can checkout the details here.

Info Look And Feel 
This one is based on the Metal look and feel. This is the one that you will find in most enterprise or commercial Java Apps. It’s designed to have a slim, clean appearance. It has support for themes. Works best for Windows, though looks decent on KDE as well. Download

Pgs Look And Feel 
I would call this a windows and KDE/Gnome hybrid. It aims be a very modern cross-platform LAF with nice features. the UI components are not as-sleek-as-others. Download

Quaqua Look And Feel 
The Quaqua LAF is an user interface library which adheres closest to Mac OS X. Download

Casual Themes

Oyaha
This one is a cool and trendy. It’s unique, as it features transparency, sounds and is Skinable. For the cool generations. Download

Liquid Look And Feel 
Liquid gives the application a crystal effect on the buttons. It’s based on Mosfet’s Liquid 0.9.6 theme for KDE 3.x. Reminds of Candy theme from StyleXP. Download

JTattoo 
JTattoo is skinnable and consists of several different LAF. User can customize the look by choosing among different available color schemes. Download

Make Java applications more attractive, and encourage Open Source, cheers.

I`ll keep on updating the list. Make sure you check back.

Do you know of any others? I`ll be happy to include them. Follow me on Twitter.



Read more: http://geeknizer.com/best-java-swing-look-and-feel-themes-professional-casual-top-10/#ixzz2BDBGfoLk

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

JAVA TCP 통신 예제  (0) 2012.11.17
Java 계산기 레이아웃  (0) 2012.11.17
setLookAndFeel 예제  (0) 2012.11.04
JAVA Applet Chatting Client  (0) 2012.07.26
Java 채팅 코드  (0) 2012.07.25

JAVA Applet Chatting Client

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

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

JAVA TCP 통신 예제  (0) 2012.11.17
Java 계산기 레이아웃  (0) 2012.11.17
setLookAndFeel 예제  (0) 2012.11.04
JAVA Look and Feel 활용 사이트  (0) 2012.11.04
Java 채팅 코드  (0) 2012.07.25

Java 채팅 코드

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

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

JAVA TCP 통신 예제  (0) 2012.11.17
Java 계산기 레이아웃  (0) 2012.11.17
setLookAndFeel 예제  (0) 2012.11.04
JAVA Look and Feel 활용 사이트  (0) 2012.11.04
JAVA Applet Chatting Client  (0) 2012.07.26