Android 채팅 소스 02

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

package com.tistory.tansanc.Test130805;

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 android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {
	String msg;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	public void mOnClick(View v) {
		EditText editText1 = (EditText) findViewById(R.id.editText1);
		msg = editText1.getText().toString();
		MessageSendThread mst = new MessageSendThread();
		mst.start();
	}

	class MessageSendThread extends Thread {
		public void run() {
			Socket socket = null;
			PrintWriter out = null;
			BufferedReader in = null;

			try {
				socket = new Socket("115.20.247.141", 2013);
				out = new PrintWriter(socket.getOutputStream(), true);
				in = new BufferedReader(new InputStreamReader(
						socket.getInputStream()));

				out.println(msg);
				String receiveString = in.readLine();
				Message message = new Message();
				message.obj = receiveString;
				mHandler.sendMessage(message);

				out.close();
				in.close();
				socket.close();
			} catch (UnknownHostException e) {
			} catch (IOException e) {
			}
		}
	}

	Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			String receiveString = (String)msg.obj;
			TextView textView1 = (TextView)findViewById(R.id.textView1)	;
			textView1.setText(textView1.getText() + "\n" + receiveString);
		}
	};
}


'Programming > Android' 카테고리의 다른 글

Android 채팅 서버 소스 01  (0) 2013.08.20
Android 채팅 소스 03  (0) 2013.08.20
Android 채팅 소스 01  (0) 2013.08.20
Android Download html  (0) 2013.08.20
Andoid 매트로돔  (0) 2013.08.19

Android 채팅 소스 01

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

package com.tistory.tansanc.Test130805;

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 android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {
	String msg;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	public void mOnClick(View v) {
		EditText editText1 = (EditText) findViewById(R.id.editText1);
		msg = editText1.getText().toString();
		MessageSendThread mst = new MessageSendThread();
		mst.start();
	}

	class MessageSendThread extends Thread {
		public void run() {
			Socket socket = null;
			PrintWriter out = null;
			BufferedReader in = null;

			try {
				socket = new Socket("115.20.247.141", 2013);
				out = new PrintWriter(socket.getOutputStream(), true);
				in = new BufferedReader(new InputStreamReader(
						socket.getInputStream()));

				out.println(msg);

				out.close();
				in.close();
				socket.close();
			} catch (UnknownHostException e) {
			} catch (IOException e) {
			}
		}
	}
}


'Programming > Android' 카테고리의 다른 글

Android 채팅 소스 03  (0) 2013.08.20
Android 채팅 소스 02  (0) 2013.08.20
Android Download html  (0) 2013.08.20
Andoid 매트로돔  (0) 2013.08.19
Android 시계  (0) 2013.08.19

Android Download html

Programming/Android 2013. 8. 20. 16:43 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package com.tistory.tansanc.Test130805;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.c21_downhtml);

		Button btn = (Button) findViewById(R.id.down);
		btn.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				String html;
				DownloadHtmlThread.start();
			}
		});
	}

	// * 자바의 네트워크 클래스 사용
	Thread DownloadHtmlThread = new Thread() {
		public void run() {
			StringBuilder html = new StringBuilder();
			try {
				URL url = new URL("http://www.google.com");
				HttpURLConnection conn = (HttpURLConnection) url
						.openConnection();
				if (conn != null) {
					conn.setConnectTimeout(10000);
					conn.setUseCaches(false);
					if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
						BufferedReader br = new BufferedReader(
								new InputStreamReader(conn.getInputStream()));
						for (;;) {
							String line = br.readLine();
							if (line == null)
								break;
							html.append(line + '\n');
						}
						br.close();
					}
					conn.disconnect();
				}
			} catch (Exception ex) {
				Log.d("Exceoption", ex.toString());
			}
			Message msg = new Message();
			msg.obj = html.toString();
			mHandler.sendMessage(msg);
		};
	};
	Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {

			String str = (String)msg.obj; 
			TextView result = (TextView) findViewById(R.id.result);
			result.setText(str);
		};
	};

	// */

	/*
	 * 아파치 클래스 사용 String DownloadHtml(String addr) { HttpGet httpget = new
	 * HttpGet(addr); DefaultHttpClient client = new DefaultHttpClient();
	 * StringBuilder html = new StringBuilder(); try { HttpResponse response =
	 * client.execute(httpget); BufferedReader br = new BufferedReader(new
	 * InputStreamReader(response.getEntity().getContent())); for (;;) { String
	 * line = br.readLine(); if (line == null) break; html.append(line + '\n');
	 * } br.close(); } catch (Exception e) {;} return html.toString(); } //
	 */
}


'Programming > Android' 카테고리의 다른 글

Android 채팅 소스 02  (0) 2013.08.20
Android 채팅 소스 01  (0) 2013.08.20
Andoid 매트로돔  (0) 2013.08.19
Android 시계  (0) 2013.08.19
Andoid 알람 기능으로 라디오 mms 주소로 듣기  (0) 2013.08.16

Andoid 매트로돔

Programming/Android 2013. 8. 19. 17:21 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
package com.tistory.tansanc.Test130805;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;

public class MainActivity extends Activity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
		mDdok = mPool.load(this, R.raw.ddok, 1);
		MyView mv = new MyView(this, mHandler);
		setContentView(mv);
	}

	Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			mPool.play(mDdok, 1, 1, 0, 0, 1);
		}
	};

	SoundPool mPool;
	int mDdok;

	class MyView extends View {
		Context context;
		Handler mDdokHandler;

		public MyView(Context context, Handler mDdokHandler) {
			super(context);
			this.context = context;
			this.mDdokHandler = mDdokHandler;
			mHandler.sendEmptyMessage(0);
		}

		float degree = 0;
		float inc = 1;

		@Override
		protected void onDraw(Canvas canvas) {
			// TODO Auto-generated method stub

			Paint Pnt = new Paint();
			Pnt.setAntiAlias(true);
			Pnt.setColor(Color.RED);
			Pnt.setStrokeWidth(20);

			canvas.translate(canvas.getWidth() / 2, canvas.getHeight() / 4 * 3);
			if (degree > 45) {
				inc = -1;
				mDdokHandler.sendEmptyMessage(0);
			} else if (degree < -45) {
				inc = 1;
				mDdokHandler.sendEmptyMessage(0);
			}
			canvas.rotate(degree);
			canvas.drawLine(0, 0, 0, -canvas.getHeight() / 2, Pnt);
			super.onDraw(canvas);
		}

		Handler mHandler = new Handler() {
			public void handleMessage(Message msg) {
				degree = degree + inc;
				invalidate();
				mHandler.sendEmptyMessageDelayed(0, 50);
			}
		};
	}
}

'Programming > Android' 카테고리의 다른 글

Android 채팅 소스 01  (0) 2013.08.20
Android Download html  (0) 2013.08.20
Android 시계  (0) 2013.08.19
Andoid 알람 기능으로 라디오 mms 주소로 듣기  (0) 2013.08.16
Android 라디오 mms 주소로 듣기  (1) 2013.08.16

Android 시계

Programming/Android 2013. 8. 19. 16:59 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
package com.tistory.tansanc.Test130805;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;

public class MainActivity extends Activity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyView mv = new MyView(this);
		setContentView(mv);
	}
}

class MyView extends View {
	Context context;

	public MyView(Context context) {
		super(context);
		this.context = context;
		mHandler.sendEmptyMessage(0);
	}

	float degree = -30;

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub

		Paint Pnt = new Paint();
		Pnt.setAntiAlias(true);
		Pnt.setColor(Color.YELLOW);
		Pnt.setStrokeWidth(20);
		
		canvas.translate(canvas.getWidth()/2, canvas.getHeight()/2);
		canvas.rotate(degree);
		canvas.drawLine(0, 0, 400, 400, Pnt);
		Pnt.setColor(Color.RED);
		Pnt.setStrokeWidth(10);
		canvas.rotate(degree);
		canvas.drawLine(0, 0, 400, 400, Pnt);
		super.onDraw(canvas);
	}

	Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			degree++;
			invalidate();
			mHandler.sendEmptyMessageDelayed(0, 100);
		}
	};
}

'Programming > Android' 카테고리의 다른 글

Android Download html  (0) 2013.08.20
Andoid 매트로돔  (0) 2013.08.19
Andoid 알람 기능으로 라디오 mms 주소로 듣기  (0) 2013.08.16
Android 라디오 mms 주소로 듣기  (1) 2013.08.16
Android Intro 로딩 Activity  (0) 2013.08.12
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package com.example.alarm;

import java.util.Calendar;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

public class MainActivity extends Activity {
	DatePicker mDate;
	TextView mTxtDate;
	TimePicker mTime;
	TextView mTxtTime;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		mDate = (DatePicker)findViewById(R.id.datepicker);
		mDate.init(mDate.getYear(), mDate.getMonth(), mDate.getDayOfMonth(),
				new DatePicker.OnDateChangedListener() {
					public void onDateChanged(DatePicker view, int year,
							int monthOfYear, int dayOfMonth) {
						mTxtDate.setText(String.format("%d/%d/%d", year,
								monthOfYear + 1, dayOfMonth));
					}
				});

		// 시간 선택기
		mTime = (TimePicker) findViewById(R.id.timepicker);
		mTxtTime = (TextView) findViewById(R.id.txttime);
		mTime.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
			public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
				mTxtTime.setText(String.format("%d:%d", hourOfDay, minute));
			}
		});

		// 24시간제 토글
		findViewById(R.id.btntoggle24).setOnClickListener(
				new View.OnClickListener() {
					public void onClick(View v) {
						mTime.setIs24HourView(!mTime.is24HourView());
					}
				});
	}

	public void mOnClick(View v) {

		String result = String.format("%d/%d/%d %d:%d", mDate.getYear(),
				mDate.getMonth() + 1, mDate.getDayOfMonth(),
				mTime.getCurrentHour(), mTime.getCurrentMinute());
		Toast.makeText(MainActivity.this, result + "로 알람이 설정 되었습니다.", 0).show();

		// 알람 매니저에 등록할 인텐트를 만듬

		Intent intent = new Intent(this, AlarmReceiver.class);

		PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, 0);

		// 알람을 받을 시간을 5초 뒤로 설정

		Calendar calendar = Calendar.getInstance();

		calendar.setTimeInMillis(System.currentTimeMillis());

		calendar.add(Calendar.SECOND, 50);

		// 알람 매니저에 알람을 등록

		AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

		am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);

	}

}



package com.example.alarm;

import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;

public class AlarmReceiver extends BroadcastReceiver {
	public void onReceive(Context context, Intent intent) {
		Toast.makeText(context, "It's time to start", Toast.LENGTH_LONG).show();
		Intent i = new Intent(Intent.ACTION_VIEW);
		Uri uri = Uri.parse("mms://114.108.140.39/magicfm_live");
		i.setDataAndType(uri, "video/mp4");
		
		PendingIntent pi = PendingIntent.getActivity(context, 0, i,
				PendingIntent.FLAG_ONE_SHOT);
		try {
			pi.send();
		} catch (CanceledException e) {
			e.printStackTrace();
		}

	}
}







    

    

    
        
            
                

                
            
        

        
        
    





'Programming > Android' 카테고리의 다른 글

Andoid 매트로돔  (0) 2013.08.19
Android 시계  (0) 2013.08.19
Android 라디오 mms 주소로 듣기  (1) 2013.08.16
Android Intro 로딩 Activity  (0) 2013.08.12
Android 전화번호부 목록 ListView에 띄우기  (0) 2013.08.09

Android 라디오 mms 주소로 듣기

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

package com.tistory.tansanc.Test130805;

import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends Activity implements OnPreparedListener {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

	}

	MediaPlayer player;

	public void mOnClick(View v) {

		try {
			Intent it = new Intent(Intent.ACTION_VIEW);
			Uri uri = Uri.parse("mms://114.108.140.39/magicfm_live");
			it.setDataAndType(uri, "video/mp4");
			startActivity(it);
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void onPrepared(MediaPlayer player) {
		Log.d("Start onPrepared", "Start onPrepared");
		player.start();
	}
}

JAVA 계산기 프로그램 부분완성

Programming/JAVA,JSP 2013. 8. 16. 14:25 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
package com.tansanc.tistory;

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);

	}

	String operand1;
	String operator;
	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() == pl)
			{
				operand1 = t1.getText();
				operator = "+";
				t1.setText("");
			}
			else if( e.getSource() == cal)
			{
				if(operator == "+")
				{
					t1.setText("" + ( Integer.parseInt(operand1) + Integer.parseInt(t1.getText())) );
				}
			}
		}
	}

}

public class CardTest
{

	public static void main(String[] args)
	{

		Cal Cals = new Cal();

	}

}

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

JAVA 채팅 프로그램 소스  (0) 2013.08.23
JAVA 채팅 클라이언트  (0) 2013.08.23
JAVA 계산기 레이아웃  (0) 2013.08.16
JAVA 타자연습 프로그램  (0) 2013.08.13
JAVA Console Token 구현  (0) 2013.08.07

JAVA 계산기 레이아웃

Programming/JAVA,JSP 2013. 8. 16. 13:30 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
package com.tansanc.tistory;

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 CardTest
{

	public static void main(String[] args)
	{

		Cal Cals = new Cal();

	}

}

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

JAVA 채팅 클라이언트  (0) 2013.08.23
JAVA 계산기 프로그램 부분완성  (0) 2013.08.16
JAVA 타자연습 프로그램  (0) 2013.08.13
JAVA Console Token 구현  (0) 2013.08.07
JAVA 제네릭을 사용한 Store Class  (0) 2013.08.07

JAVA 타자연습 프로그램

Programming/JAVA,JSP 2013. 8. 13. 12:18 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
package com.tansanc.tistory;

import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.Random;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

class MyFrame extends JFrame implements KeyListener
{
	JLabel staticText;
	JTextField inputText;
	JLabel resultText;
	long start;
	long end;
	String problemArray[] =
	{ "JAVA", "안녕하세요" };
	ArrayList problemList = new ArrayList();

	public MyFrame()
	{
		problemList.add("JAVA");
		problemList.add("안녕하세요");
		this.setSize(300, 200);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("이벤트 예제");
		staticText = new JLabel("Hello World");
		add(staticText, BorderLayout.NORTH);
		inputText = new JTextField("");
		add(inputText, BorderLayout.CENTER);
		resultText = new JLabel("Hello World");
		add(resultText, BorderLayout.SOUTH);

		inputText.addKeyListener(this);

		setVisible(true);
		start = System.currentTimeMillis();
	}

	@Override
	public void keyPressed(KeyEvent e)
	{
	}

	@Override
	public void keyReleased(KeyEvent e)
	{

	}

	@Override
	public void keyTyped(KeyEvent e)
	{
		if (staticText.getText().equals(inputText.getText()))
		{
			Random r = new Random();
			end = System.currentTimeMillis();
			resultText.setText("정답입니다. " + inputText.getText().length()
					/ ((end - start) / 1000.0 / 60.0));
			staticText.setText(problemList.get(r.nextInt(2)));
			inputText.setText("");
		}
	}
}

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

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

JAVA 계산기 프로그램 부분완성  (0) 2013.08.16
JAVA 계산기 레이아웃  (0) 2013.08.16
JAVA Console Token 구현  (0) 2013.08.07
JAVA 제네릭을 사용한 Store Class  (0) 2013.08.07
JAVA DRAG 가능한 Component 만들기  (0) 2013.08.03