Jump to content

Welcome to [ iT ] Forums
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!
Cộng đồng Âm nhạc Việt Nam

Hình ảnh

Một số code của các chương trình cơ bản trong Java

- - - - -

  • Chủ Đề Đã Khóa Chủ đề này đã được khóa
64 replies to this topic

#41
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Chương trình sau tạo ra một lớp Vector vect. Nó chứa 6 phần tử: “Numbers In Words”, “One”, “Two”, “Three”, “Four”, “Five”. Phương thức removeElement()được sử dụng để xoá các phần tử từ vect
Posted Image

import java.util.*;
public class VectorImplementation
{
 public static void main(String args[])
 {
  Vector vect = new Vector();
  vect.addElement(“One”);
  vect.addElement(“Two”);
  vect.addElement(“Three”);
  vect.addElement(“Four”);
  vect.addElement(“Five”);
  vect.insertElementAt(“Numbers In Words”,0);
  vect.insertElementAt(“Four”,4);
  System.out.println(“Size: “+vect.size());
  System.out.println(“Vector “);
  for(int i = 0; i<vect.size(); i++)
	  {
   		 System.out.println(vect.elementAt(i)+” , “);
	  }
 vect.removeElement(“Five”);
  System.out.println(“”);
  System.out.println(“Size: “+vect.size());
  System.out.println(“Vector “);
  for(int i = 0;i<vect.size();i++)
  {
   System.out.print(vect.elementAt(i)+ “ , “);
  }
 }
}

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#42
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Trong chương trình này, hai đối tượng StringTokenizer đã được tạo ra. Đầu tiên, “st1” được sử dụng để phân tách một biểu thức toán học. Thứ hai, “st2” phân tách một dòng của các trường được phân cách bởi dấu phẩy. Cả hai tokenizer, phương thức hasMoreTokens() và nextToken() được sử dụng đế duyệt qua tập các token, và hiển thị các token.
Posted Image

import java.util.*;
public class StringTokenizerImplementer
{
 public static void main(String args[])
 	{
  // đặt một biểu thức toán học và tạo một tokenizer cho chuỗi đó.
  String mathExpr = “4*3+2/4”;
  StringTokenizer st1 = new StringTokenizer(mathExpr,”*+/-“, true);
  //trong khi vẫn còn các token, hiển thị 	 System.out.println(“Tokens of  mathExpr: “);
 	 while(st1.hasMoreTokens())
 	 System.out.println(st1.nextToken());
  //tạo một chuỗi của các trường được phân cách bởi dấu phẩy và tạo //một tokenizer cho chuỗi.
  String commas = “field1,field2,field3,and field4”;
 	 StringTokenizer st2 = new StringTokenizer(commas,”,”,false);
 	//trong khi vẫn còn token, hiển thị.
 System.out.println(“Comma-delimited tokens : “);
while (st2.hasMoreTokens())
System.out.println(st2.nextToken());
 	}
}

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#43
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Viết giao diện chương trình trò chơi puzzle như sau:
Posted Image

import java.awt.*;
class GamePuzzle extends Frame
{
	Button btn[];
	String str[]={"","1","2","3","4","5","6",
	"7","8","9","10","11","12","13","14","15"};
	public GamePuzzle (String title)
	{
		super(title);
		setLayout(new GridLayout(4,4));
		btn = new Button[str.length];
		for (int i=0;i<str.length;i++)
		{
			btn[15-i]=new Button(str[15-i]);
			add(btn[15-i]);
		}
	}
	public static void main(String args[])
	{
		GamePuzzle gp = new GamePuzzle("Grid Layout");
		gp.setSize(300,200);
		gp.show();
		
	}
}

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#44
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Viết một applet cho phép nhập 1 chuỗi và kiểm tra nó như hình
Posted Image

import java.applet.Applet;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class TokenTest extends Applet implements ActionListener
{
	Label prompt;
	TextField input;
	TextArea output;
	public void init()
	{
		prompt = new Label("Go Vao Mot Cau Roi Nhan Enter");
		input = new TextField(50);
		input.addActionListener(this);
		output = new TextArea(10,30);
		output.setEditable(false);
		add(prompt);
		add(input);
		add(output);
	}	
	public void actionPerformed(ActionEvent e)
	{
		String stringToTokenize = e.getActionCommand();
		StringTokenizer tokens = new StringTokenizer(stringToTokenize);
		output.setText("");
		output.append("So luong phan tu:"+tokens.countTokens()+"\nCac Token gom co:\n");
		while(tokens.hasMoreTokens())
		output.append(tokens.nextToken()+"\n");
	}
}

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#45
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Tạo 1 chương trình chia bài (tiến lên ấy)
Posted Image

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class DeckOfCards extends Applet implements ActionListener
{
	private Card deck[];
	private int currentCard;
	private Button dealButton, shuffleButton;
	private TextField displayCard;
	public void init()
	{
		String faces[] = {"A","2","3","4","5","6","7","8",
						"9","10","J","Q","K"};
		String suits[]={"Co","Ro","Chuon","Bich"};
		deck = new Card[52];
		currentCard = -1;
		for (int i = 0; i<deck.length;i++)
		deck[i]= new Card(faces[i%13], suits[i/13]);
		dealButton = new Button("Chia Bai");
		dealButton.addActionListener(this);
		shuffleButton = new Button("Xao bai");
		shuffleButton.addActionListener(this);
		displayCard = new TextField(30);
		displayCard.setEditable(false);
		add(dealButton);
		add(shuffleButton);
		add(displayCard);
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()== dealButton)
		{
			Card dealt = dealCard();
			if(dealt != null)
			{
				displayCard.setText(dealt.toString());
				showStatus("La bai thu: "+(currentCard + 1));
			}
			else
			{
				displayCard.setText("DA CHIA HET BO BAI");
				showStatus("Xao bai de tiep tuc");
			}
		}
		else 
		if(e.getSource() == shuffleButton)
		{
			displayCard.setText("XAO BAI ...");
			showStatus("");
			shuffle();
			displayCard.setText("BAI DA DUOC XAO");
		}
	}
	public void shuffle()
	{
		currentCard = -1;
		for (int i=0;i<deck.length;i++)
		{
			int j= (int)(Math.random()*52);
			Card temp = deck[i];//Hoan CHuyen
			deck[i]= deck[j];
			deck[j] = temp;
		}
		dealButton.setEnabled(true);
	}
	public Card dealCard()
	{
	if(++currentCard < deck.length)
	return deck[currentCard];
	else
	{
		dealButton.setEnabled(false);
		return null;
	}	
	}
}
class Card
{
	private String face;
	private String suit;
	public Card(String f,String s)
	{
		face =f;
		suit=s;
	}
	public String toString(){return face + "" + suit;}
}
<html>
<applet code=DeckOfCards width=300 height=150>
</applet>
</html>

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#46
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Sửa lại bài trên sao cho mỗi lần người chơi nhấn nút dealButton , phương thức dealCard sẽ chia một tay bài xì phé (poker) gồm 5 lá . Sau đó viết thêm 1 số phương thức thực hiện các nhiệm vụ sau :
1>Xác định xem bài hiện hành có chứa pair (đôi) nào không
2>Xác định xem tay bài hiện hành có chứa two pairs (hai đôi) nào không
3>Xác định xem tay bài hiện hành có chứa three ò a kind(tam cô) không
4>Xác định xem tay bài hiện hành có chứa four o a kind (tứ quý) không
5>Xác định xem tay bài hiện hành có chứa flush (thùng) không
6>Xác định xem tay bài hiện hành có chứa straight (sảnh) không
Posted Image

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Poker extends Applet implements ActionListener
{
	private Card deck[], hand[];
	private int currentCard;
	private Button dealButton, shuffleButton;
	private TextArea displayCard;
	private String faces[],suits[],output;
	private int numbers[];
public void init()
{
	String f[]={"A","2","3","4","5","6","7","8",
						"9","10","J","Q","K"};
	String s[]={"Co","Ro","Chuon","Bich"};
	numbers = new int[13];
	faces = f;
	suits = s;
	hand = new Card[5];
	deck = new Card[52];
	currentCard = -1;
	for (int i = 0; i<deck.length;i++)
		deck[i]= new Card(faces[i%13], suits[i/13]);
	dealButton = new Button("Chia tay bai");	
	shuffleButton = new Button("Xao bai");
	dealButton.addActionListener(this);
	shuffleButton.addActionListener(this);
	displayCard = new TextArea(7,20);
	displayCard.setEditable(false);
	add(dealButton);
	add(shuffleButton);
	add(displayCard);
}
public void actionPerformed(ActionEvent event)
{
	if(event.getSource()== dealButton)
	{
		displayCard.setText("");//Xoa TextArea
		showStatus("");//Xoa thanh trang thai
		output="";
		
		for(int n=0;n<hand.length;n++)
		{
			Card temp = dealCard();
			
			if(temp !=null)
			{
				hand[n] = temp;
				displayCard.append(hand[n].toString() + "\n");
			}
		}
		totalHand(); // Tinh toan noi dung cua tay bai hien hanh
		
		pair();
		threeOfAKind();
		fourOfAKind();
		straight();
		flush();
	}
	else 
	if (event.getSource()== shuffleButton)
	{
		shuffle();
		displayCard.setText("BO BAI DA DUOC XAO\n");
	}
}
public void shuffle()
{
	currentCard = -1;
	
	for(int i=0;i<deck.length;i++)
	{
		int j = (int)(Math.random()*52);
		
		Card temp = deck[i];
		deck[i]= deck[j];
		deck[j]= temp;
	}
	dealButton.setEnabled(true);
}
public Card dealCard()
{
	if(currentCard > 50)
	{
		dealButton.setEnabled(false);
		showStatus("");//Xoa hai la bai sau cung
		return null;
	}
	else
	if(++currentCard < deck.length)
	return deck[currentCard];
	
	return null; // Chi la hinh thuc de danh lua trinh bien dich
}
private void totalHand()
{
	for(int x = 0;x < faces.length; x++)
	numbers[x]=0;
	
	for(int h=0;h<hand.length;h++)
	for(int f= 0;f<faces.length;f++)
	if(hand[h].getFace().equals(faces[f]))
		++numbers[f];
}

public void pair()
{
	for(int k = 0; k<faces.length;k++)
	if(numbers[k] ==2)
	output += ("Doi"+faces[k]);
	
	showStatus(output);
}

public void threeOfAKind()
{
	for(int k=0;k<faces.length;k++)
	if(numbers[k] ==3)
	{
		output +=("Tam co"+faces[k]);
		break;
	}
	
	showStatus(output);
}

public void fourOfAKind()
{
	for(int k=0;k<faces.length;k++)
	if(numbers[k]==4)
	output+=("Tu quy"+faces[k]);
	
	showStatus(output);
}

public void flush()
{
	String theSuit = hand[0].getSuit();
	
	for(int s=1;s<hand.length;s++)
	if(hand[s].getSuit().compareTo(theSuit) != 0)
	return;//Khong phai thung
	
	output +=("Thung "+ theSuit);
	showStatus(output);
}

public void straight()
{
	int locations[] = new int[5],z=0;
	
	for(int y=0;y<numbers.length;y++)
	if(numbers[y]==1)
	locations[z++]=y;
	
	bubbleSort(locations);
	
	int faclevelue = locations[0];
	
	for(int m=1;m<locations.length;m++)
	{
		if(faclevelue != locations[m]-1)
		return;
		else
		faclevelue = locations[m];
	}
	
	output +="Sanh";
	showStatus(output);
}

private void bubbleSort(int values[])
{
	for(int pass=1;pass<values.length;pass++)
	for(int comp=0;comp<values.length-1;comp++)
	if(values[comp]>values[comp+1])
	{
		int temp=values[comp];
		values[comp]=values[comp + 1];
		values[comp + 1] = values[comp];
	}
}
}
//Lop Card
class Card
{
	private String face;
	private String suit;
	
	public Card(String f , String s)
	{
		face = f;
		suit = s;
	}
	
	public String getFace(){return face;}
	public String getSuit(){return suit;}
	public String toString(){return face +" "+suit;}
}
<html>
<body>
<applet  code = Poker width=400 height=400></applet>
</body>
</html>

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#47
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

So sánh hai chuỗi do người dùng nhập vào
Posted Image

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class CompareStrings extends Applet implements ActionListener
{
	private Label prompt1, prompt2;
	private TextField input1,input2;
	
	public void init()
	{
		prompt1 = new Label("Hay go vao chuoi dau tien:");
		prompt2 = new Label("Hay go vao chuoi thu hai: ");
		input1= new TextField(20);
		input2=new TextField(20);
		input2.addActionListener(this);
		
		add(prompt1);
		add(input1);
		add(prompt2);
		add(input2);
	}
	public void actionPerformed(ActionEvent e)
	{
		String first = input1.getText();
		String second = input2.getText();
		int value= first.compareTo(second);
		
		if(value ==0)
			showStatus(first+"=="+second);
			else
				if(value>0)
				showStatus(first+">"+second);
			else
				showStatus(first+"<"+second);
	}
}
<html>
<applet code=CompareStrings  width=400 height=300>
</applet>
</html>

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#48
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Viết 1 applet cho phép người dùng nhập 1 đoạn Text (không có khoảng trắng trong 1 TextField và hiển thị kết quả sắp xếp trong 1 TextArea theo thứ tự ABC
Ví dụ ta nhập các chữ cái a(enter) , c(enter) sau đó nhập b (enter) thì b tự chèn vào giữa a và c theo bảng chữ cái
Posted Image

import java.applet.Applet;
import java.util.*;
import java.awt.*;
import java.awt.event.*;

public class SortThem extends Applet implements ActionListener
{
	private TextField input;
	private Label prompt;
	private TextArea output;
	
	public void init()
	{
		input = new TextField(10);
		input.addActionListener(this);
		output = new TextArea(10,10);
		prompt = new Label("Hay nhap vao mot chuoi");
		
		add(prompt);
		add(input);
		add(output);
	}
	public void actionPerformed(ActionEvent e)
	{
		String newString = input.getText();
		String oldString = output.getText();
		StringTokenizer t = new StringTokenizer(oldString);
		int number = t.countTokens(),c=0;
		String tokens[] = new String[number+1];
		
		input.setText("");
		output.setText("");
		
		while(t.hasMoreTokens()&&c<number)
		tokens[c++] = t.nextToken();
		
		tokens[c]= newString;
		bubbleSort(tokens);
		
		for(int k =0;k<tokens.length;k++)
		output.append(tokens[k]+"\n");
	}
	private void bubbleSort(String s[])
	{
		for(int pass = 1;pass<s.length;pass++)
		for(int c=0;c<s.length-pass;c++)
		if(s[c].compareTo(s[c+1])>0)
		{
			String temp = s[c];
			s[c]=s[c+1];
			s[c+1]=temp;
		}
	}
}
<html>
<applet code=SortThem  width=400 height=300>
</applet>
</html>

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#49
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Chương trình đếm số lần xuất hiện 1 kí tự trong chuỗi
Posted Image

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class Index extends Applet implements ActionListener
{
	private TextField inputKey;
	private Label promptKey;
	private TextArea input;
	private int count;
	
	public void init()
	{
		inputKey = new TextField(4);
		inputKey.addActionListener(this);
		promptKey = new Label("Hay nhap vao mot ki tu:");
		input = new TextArea(4,20);
		add(promptKey);
		add(inputKey);
		add(input);
	}
	
	public void actionPerformed(ActionEvent e)
	{
		count = 0;
		String key = e.getActionCommand().toString();
		String s =input.getText();
		int last = -2,current = 0;
		
		for(int j= -1;j<s.length();)
		{
			current=s.indexOf(key.charAt(0),++j);
			
			if (current != -1 && current != last)
			{
				last = current;
				count++;
			}
		}
		showStatus("So luong ki tu"+" "+key.charAt(0) +" "+":"+" "+count);
	}
}
<html>
<body>
<applet  code = Index width=400 height=400></applet>
</body>
</html>

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#50
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Chương trình kiểm tra chuỗi có phải bắt đầu bằng chữ "b" thì cho kết quả vào một TextArea
Posted Image

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class FirstB extends Applet implements ActionListener
{
	private TextField input;
	private Label prompt, valueArea;
	private TextArea display;
			Panel pDetails;
					
	public void init()
	{
		pDetails = new Panel();
		input = new TextField();
		input.addActionListener(this);
		prompt = new Label("Hay nhap vao mot chuoi: ");
		valueArea = new Label("Ket qua:");
		display = new TextArea(4,20);
		pDetails.setLayout(new GridLayout(2,2));
		pDetails.add(prompt);
		pDetails.add(input);
		pDetails.add(valueArea);
		pDetails.add(display);
		add(pDetails);
			}
	
	public void actionPerformed(ActionEvent e)
	{
		String s=e.getActionCommand().toString();
		
		if(s.startsWith("b"))
		display.append(s+"\n");
	}
}
<html>
<body>
<applet  code = FirstB width=400 height=400></applet>
</body>
</html>

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#51
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Viết 1 applet như hình
Posted Image

package mypackage;
import java.text.DecimalFormat;//Dung trong viec dinh dang so

public class Time3
{
	private int hour;
	private int minute;
	private int second;
	
	public Time3()
	{
		setTime(0,0,0);
	}
	public Time3(int h)
	{
		setTime(h,0,0);
	}
	public Time3(int h,int m)
	{
		setTime(h,m,0);
	}
	public Time3(int h,int m,int s)
	{
		setTime(h,m,s);
	}
	public void setTime(int h,int m,int s)
	{
		setHour(h);
		setMinute(m);
		setSecond(s);
	}
	public void setHour(int h)
	{
		hour=((h>=0 && h<24)?h:0);
	}
	public void setMinute(int m)
	{
		minute=((m>=0 && m<60)?m:0);
	}
	public void setSecond(int s)
	{
		second=((s>=0 && s<60)?s:0);
	}
	public int getHour()
	{
		return hour;
	}
	public int getMinute()
	{
		return minute;
	}
	public int getSecond()
	{
		return second;
	}
	public String toMilitaryString()
	{
		DecimalFormat twoDigits = new DecimalFormat("00");
		
		return twoDigits.format(hour)+
				twoDigits.format(minute);
	}
	public String toString()
	{
		DecimalFormat twoDigits = new DecimalFormat("00");
		
		return((hour==12||hour==0)?hour:hour%12) +
				":"+twoDigits.format(minute)+
				":"+twoDigits.format(second)+
				(hour<12 ?"AM":"PM");
	}
	
}
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import mypackage.Time3;

public class TimeTest extends Applet implements ActionListener
{
	private Time3 t;
	private Label hourLabel,minuteLabel,secondLabel;
	private TextField hourField,minuteField,secondField,display;
	private Button tickButton;
	
	public void init()
	{
		t= new Time3();
		
		hourLabel = new Label("Dat gio");
		hourField = new TextField(10);
		hourField.addActionListener(this);
		add(hourLabel);
		add(hourField);
		
		minuteLabel = new Label("Dat phut");
		minuteField = new TextField(10);
		minuteField.addActionListener(this);
		add(minuteLabel);
		add(minuteField);
		
		secondLabel = new Label("Dat giay");
		secondField = new TextField(10);
		secondField.addActionListener(this);
		add(secondLabel);
		add(secondField);
		
		display = new TextField(30);
		display.setEditable(false);
		add(display);
		
		tickButton = new Button("Tang Giay Len 1");
		tickButton.addActionListener(this);
		add(tickButton);
		
		updateDisplay();
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==tickButton)
		tick();
		else if(e.getSource()==hourField)
		{
			t.setHour(Integer.parseInt(e.getActionCommand()));
			hourField.setText("");
		}
		else if(e.getSource()==minuteField)
		{
			t.setMinute(Integer.parseInt(e.getActionCommand()));
			minuteField.setText("");
		}
		else if(e.getSource()==secondField)
		{
			t.setSecond(Integer.parseInt(e.getActionCommand()));
			secondField.setText("");
		}
		
		updateDisplay();
	}
	
	public void updateDisplay()
	{
		display.setText("Hour:"+t.getHour()+
						";Minute"+t.getMinute()+
						";Second"+t.getSecond());
		showStatus("Thoi gian chuan: "+t.toString()+
					"; Thoi Gian Quan DOi:"+t.toMilitaryString());
	}
	
	public void tick()
	{
		t.setSecond((t.getSecond()+1)%60);
		
		if(t.getSecond()==0)
		{
			t.setMinute((t.getMinute()+1)%60);
			
			if(t.getMinute()==0)
			t.setHour((t.getHour()+1)%24);
		}
	}
}
<html>
<body>
<applet code=TimeTest width=600 height=200>
</applet>
</body>
</html>

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#52
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Viết giao diện như trong hình
Posted Image

import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.text.*;
import javax.swing.event.*; 
import javax.swing.undo.*;
import javax.swing.text.*; 
import javax.swing.KeyStroke.*;

public class subNotepad extends JFrame 
{
	
	MenuBar mb;
	Menu m1,m2,m3,m4;
	MenuItem m1i1,m1i2,m1i3,m1i4,m1i5,m1i6,m1i7;
	MenuItem m2i1,m2i2,m2i3,m2i4,m2i5,m2i6,m2i7,m2i8,m2i9,m2i10;
	MenuItem m3i1,m3i2;
	MenuItem m4i1,m4i2;
	MenuShortcut msc;
	JScrollPane jsp;
	JTextArea ta;
	String s="";
	Container c;
	UIManager.LookAndFeelInfo xx[];
	private UndoManager undo = new UndoManager();
public subNotepad(String title)
{
	super(title);
	setVisible(true);
	setSize(400,400);
	mb = new MenuBar();
	setMenuBar(mb);
	 c=getContentPane();
  c.setLayout(new BorderLayout());
  MyWindowAdapter adapter=new MyWindowAdapter(this);
  addWindowListener(adapter);
  ta=new JTextArea(s,80,80);
  c. add(ta);
  jsp=new JScrollPane(ta);
  c.add(jsp);
  msc=new MenuShortcut(79);
	
	m1 = new Menu("File");
	m1i1 = new MenuItem("New");
	m1i2 = new MenuItem("Open");
	m1i3 = new MenuItem("Save");
	m1i4 = new MenuItem("Save As...");
	m1i5 = new MenuItem("Page Setup");
	m1i6 = new MenuItem("Print");
	m1i7 = new MenuItem("Exit");
	mb.add(m1);
	m1.add(m1i1);
	m1.add(m1i2);
	m1.add(m1i3);
	m1.add(m1i4);
	m1.add(m1i5);
	m1.add(m1i6);
	m1.add(m1i7);
	
	m2 = new Menu("Edit");
	m2i1 = new MenuItem("Undo");
	m2i2 = new MenuItem("Redo");
	m2i3 = new MenuItem("Cut   Ctrl+x");
	m2i4 = new MenuItem("Copy   Ctrl+c");
	m2i5 = new MenuItem("Paste   Ctrl+v");
	m2i6 = new MenuItem("Delete   Del");
	m2i7 = new MenuItem("SelectAll");
	m2i8 = new MenuItem("Time/Date F5");
	m2i9 = new MenuItem("WordWrap");
	m2i10 = new MenuItem("Set Font...");
	mb.add(m2);
	m2.add(m2i1);
	m2.add(m2i2);
	m2.add(m2i3);
	m2.add(m2i4);
	m2.add(m2i5);
	m2.add(m2i6);
	m2.add(m2i7);
	m2.add(m2i8);
	m2.add(m2i9);
	m2.add(m2i10);	
	
	m3 = new Menu("Search");
	m3i1 = new MenuItem("Find...");
	m3i2 = new MenuItem("FindNextF3");
	mb.add(m3);
	m3.add(m3i1);
	m3.add(m3i2);
	
	m4 = new Menu("Help");
	m4i1 = new MenuItem("About Developer");
	m4i2 = new MenuItem("About Notepad");
	mb.add(m4);
	m4.add(m4i1);
	m4.add(m4i2);
	
	Document doc = ta.getDocument();
	doc.addUndoableEditListener(new UndoableEditListener() {
	public void undoableEditHappened(UndoableEditEvent evt) {
	undo.addEdit(evt.getEdit());
  }
  });
  ta.setWrapStyleWord(false);
  setSize(500,500);
  setVisible(true);
}

public static void main(String a[])
  {
   subNotepad sbn = new subNotepad("NOTEPAD");
  }
}
class MyWindowAdapter extends WindowAdapter
{
 subNotepad subNotepad;
 MyWindowAdapter(subNotepad subNotepad)
 {
  this.subNotepad=subNotepad;
 }
 public void windowClosing(WindowEvent we)
 {

  System.exit(0);
 }
}

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#53
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Posted Image

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

public class MyDialog extends JDialog {  

  public MyDialog() {
   
  final JDialog j1 = new JDialog();
  j1.setModal(true);

  JPanel p1 = new JPanel(); 
  JPanel p2 = new JPanel(); 
  JPanel p3 = new JPanel(); 
  JPanel p4 = new JPanel(); 
  JPanel p5 = new JPanel(); 
  JPanel p6 = new JPanel(); 
  JPanel p7 = new JPanel(); 

  final JProgressBar b1 = new JProgressBar(); 
  final JButton b2 = new JButton("Finish"); 
  b2.setEnabled(false); 

  final JLabel l1 = new JLabel(" Running : "); 

  p3.setLayout(new GridLayout(1,3)); 
  p3.add(p4); p3.add(b2); 
  p3.add(p5); 

  p1.setLayout(new GridLayout(6,1)); 
  p1.add(p2); p1.add(l1); 
  p1.add(b1); p1.add(p6); 
  p1.add(p3); p1.add(p7); 

  j1.getContentPane().add(p1); 
  j1.setTitle("Sample . . ."); 

  b1.setValue(0); 
  b1.setMaximum(90); 

  int delay = 500; // milliseconds 
  ActionListener progressUpdater = new ActionListener() { 
  public void actionPerformed(ActionEvent evt) { 

  int val = b1.getValue(); 
  val += 10; 

  b1.setValue(val); 
  l1.setText(" Running : "+val+" %"); 

  if(val==100) { 

  b2.setEnabled(true); 
  b2.requestFocus(); 
  j1.getRootPane().setDefaultButton(b2); 
  } 

  b2.addActionListener(new ActionListener() { 

  public void actionPerformed(ActionEvent h) 
  { 
  j1.dispose(); 
  } 
  }); 
  } 
  }; 

  new Timer(delay, progressUpdater).start(); 

  Dimension sd = Toolkit.getDefaultToolkit().getScreenSize(); 

  j1.setLocation(sd.width / 2 - 270 / 2, 
  sd.height / 2 - 150 / 2); 

  j1.setResizable(false);
  j1.setSize(270, 150); 
  j1.setVisible(true);
  }
  
  public static void main(String args[]) {

  JFrame x = new JFrame();
  Dimension sd = Toolkit.getDefaultToolkit().getScreenSize(); 

  x.setLocation(sd.width / 2 - 300 / 2, 
  sd.height / 2 - 300 / 2); 

  x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  x.setTitle("Dialog Sample . . .");
  x.setSize(300, 300);
  x.setVisible(true);

  MyDialog y = new MyDialog();
  }
}

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#54
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Posted Image

import java.io.*;
class ReadData{
	public static void main(String args[]) throws
	IOException 
		{
			BufferedReader cin = new BufferedReader( new
			InputStreamReader(System.in) );
			
			System.out.print( "Cho mot so nguyen: " );
			String st = new String( cin.readLine() );
			int a = Integer. parseInt( st );
			System.out.println( "So do la: " + a );
			
			System.out.print( "Cho mot so thuc: " );
			st = new String( cin.readLine() );
			float b = new Float( st ).floatValue();
			System.out.println( "So do la: " + b );
}
}

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#55
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Kết nối CSDL
Posted Image

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

class AddProduct extends JFrame implements ActionListener
{
	JLabel lblMa = new JLabel("Ma san pham");
	JLabel lblTen = new JLabel("Ten san pham");
	JLabel lblMota = new JLabel("Mo ta");
	JLabel lblDongia = new JLabel("Don gia(VND)");
	
	JTextField txtMa = new JTextField(20);
	JTextField txtTen = new JTextField(20);
	JTextArea taMota = new JTextArea(5,20);
	JTextField txtDongia = new JTextField(20);
	
	JButton btnAdd = new JButton("Add");
	JButton btnExit = new JButton("Exit");
	
	AddProduct()
	{
		super("Add Product");
		Container c = this.getContentPane();
		c.setLayout(new GridLayout(5,2));
		c.add(lblMa);
		c.add(txtMa);
		c.add(lblTen);
		c.add(txtTen);
		c.add(lblMota);
		c.add(taMota);
		c.add(lblDongia);
		c.add(txtDongia);
		c.add(btnAdd);
		c.add(btnExit);
		
		btnAdd.addActionListener(this);
		btnExit.addActionListener(this);
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(400,300);
		this.setVisible(true);
	}
	public void reset()
	{
		txtMa.setText("");
		txtTen.setText("");
		taMota.setText("");
		txtDongia.setText("");
	}
	public static void main(String args[])
	{
		new AddProduct();
	}
	public void actionPerformed(ActionEvent ae)
	{
		JButton btn = (JButton)ae.getSource();
		if(btn == btnAdd)
		{
			try
			{
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				Connection conn = DriverManager.getConnection("jdbc:odbc:qlbh","","");
				Statement stmt = conn.createStatement();
				
				String ma = txtMa.getText();
				String ten = txtTen.getText();
				String mota = taMota.getText();
				float dongia = Float.parseFloat(txtDongia.getText());
				String sql = "insert into sanpham (ma,ten,mota,dongia) values('"+ma+"','"+ten+"','"+mota+"',"+dongia+")";
				
				stmt.executeUpdate(sql);
				JOptionPane.showMessageDialog(this,"Them moi thanh cong");
				reset();
			}
			catch(Exception e)
				{
					e.printStackTrace();
				}
		}
		else
			System.exit(0);
	}
}

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#56
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Viết chương trình nhập điểm của 10 sinh viên trong 1 mảng sau đó in ra tổng số điểm và điểm trung bình của 10 sinh viên đó

import java.io.*;

public class Students
{
	public static void main(String args[]) throws Exception
	{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		float diem [] = new float[10];
		float s = 0;
		for(int i=0;i<10;i++)
		{
			System.out.println("Nhap vao Diem cua Sinh vien thu "+i+" : ");
			diem[i] = Float.parseFloat(in.readLine());
			s=s+diem[i];
		}
		System.out.println("Tong diem cua 10 sinh vien la: "+s);
		System.out.println("Diem trung binh cua 10 sinh vien do la: "+s/10);
	}
}

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#57
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Posted Image

import java.awt.*;
import java.awt.event.*;

public class AnotherQuiz extends Frame implements ActionListener
{
	Label label;
	TextField textField;
	Checkbox checkBox1,checkBox2,checkBox3,checkBox4;
	Button button;
	
	public AnotherQuiz(String str)
	{
		super(str);
		
		button = new Button("Done");
		button.addActionListener(this);
		textField = new TextField(25);
		Panel panel1 = new Panel();
		setLayout(new FlowLayout(FlowLayout.CENTER));
		panel1.add(button);
		panel1.add(textField);
		
		label = new Label("Label");
		checkBox1 = new Checkbox("Chechbox1",false);
		checkBox2 = new Checkbox("Chechbox2",false);
		checkBox3 = new Checkbox("Chechbox3",false);
		checkBox4 = new Checkbox("Chechbox4",false);
		Panel panel2 = new Panel();
		panel2.setLayout(new GridLayout(5,1));
		panel2.add(label);
		panel2.add(checkBox1);
		panel2.add(checkBox2);
		panel2.add(checkBox3);
		panel2.add(checkBox4);
		
		setLayout(new BorderLayout());
		add(panel1,BorderLayout.PAGE_START);
		add(panel2,BorderLayout.CENTER);
			
		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent we)
			{
				setVisible(false);
				System.exit(0);
			}
		});
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == button)
		{
			System.exit(0);
		}
	}
	
	public static void main(String args[])
	{
		AnotherQuiz obj = new AnotherQuiz("aaaaaaaaaaa");
		obj.setSize(300,300);
		obj.show();
	}
}

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#58
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Posted Image

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class ListFillup extends Applet implements ActionListener
{
	TextField textbox;
	Choice listbox;
	Button button;
	Panel p;
	
	public void init()
	{
		textbox = new TextField(20);
		listbox = new Choice();
		button = new Button("OK");
		button.addActionListener(this);
		p = new Panel();
		
		p.setLayout(new GridLayout(3,1));
		p.add(textbox);
		p.add(listbox);
		p.add(button);
		add(p);	
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == button)
		{
			String newString = textbox.getText();
			listbox.add(newString);
			textbox.setText("");
		}
	}
}

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#59
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Posted Image

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Painting extends Applet implements ActionListener,MouseListener
{
	Button redButton,blueButton;
	Button rectButton,clrcleButton,lineButton,filledButton;
	int count = 0,x1,x2,x3,x4;
	
	public void init()
	{
		redButton = new Button("Red");
		redButton.addActionListener(this);					
		blueButton = new Button("Blue");
		blueButton.addActionListener(this);
		rectButton = new Button("   Rect	");
		rectButton.addActionListener(this);
		addMouseListener(this);
		clrcleButton = new Button("  Clrcle   ");
		clrcleButton.addActionListener(this);
		addMouseListener(this);
		lineButton = new Button("   Line	");
		lineButton.addActionListener(this);
		addMouseListener(this);
		filledButton = new Button("Filled Rect");
		filledButton.addActionListener(this);
		addMouseListener(this);
		
		setLayout(new BorderLayout());
		Panel panel1 = new Panel();
		add(panel1,BorderLayout.PAGE_START);
		panel1.add(redButton);
		panel1.add(blueButton);
		Panel panel2 = new Panel();
		add(panel2,BorderLayout.PAGE_END);
		panel2.add(rectButton);
		panel2.add(clrcleButton);
		panel2.add(lineButton);
		panel2.add(filledButton);
		
	}
	public void mouseClicked(MouseEvent e)
	{
	}
	public void mousePressed(MouseEvent e)
	{
		x1= e.getX();
		x2= e.getY();
	}
	public void mouseMove(MouseEvent e)
	{
		x3= e.getX();
		x4= e.getY();
		repaint();	
	}
	public void mouseReleased(MouseEvent e)
	{
		x3= e.getX();
		x4= e.getY();
		repaint();
	}
	public void mouseEntered(MouseEvent e)
	{
	}
	public void mouseExited(MouseEvent e)
	{
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == redButton)
		{
			setBackground(Color.red);
		}
		if(e.getSource() == blueButton)
		{
			setBackground(Color.blue);
		}
		if(e.getSource() == rectButton)
		{
			count = 1;
			repaint();
		}
		if(e.getSource() == clrcleButton)
		{
			count = 2;
			repaint();
		}
		if(e.getSource() == lineButton)
		{
			count = 3;
			repaint();
		}
		/*if(e.getSource() == filledButton);
		{
			count = 4;
			repaint();
		}*/
	}
	public void paint(Graphics g)
	{
		if(count ==1)
		{
			g.drawRect(x1,x2,(x3-x1),(x4-x2));
			x3=x4=0;
		}
		if(count ==2)
		{
			g.drawOval(x1,x2,(x3-x1),(x4-x2));
			x3=x4=0;
		}
		if(count ==3)
		{
			g.drawLine(x1,x2,(x3-x1),(x4-x2));
			x3=x4=0;
		}
		/*if(count == 4)
		{
			g.drawRoundRect(x1,x2,(x3-x1),(x4-x2),(x3-x1),(x4-x2));
			x3=x4=0;
		}*/
		
	}
	
}

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->

#60
PhươngĐiệp2410

PhươngĐiệp2410

    Thạc sĩ CSTH

  • VIP
  • PipPipPipPipPip
  • 1917 Bài Viết:

Viết chương trình tính S=1-a1/1!+a2/2!-a3/3!+………+an/n! bằng ngôn ngữ java xin bà con giúp giùm em....
(Bài này 1 member hỏi mình đưa vào đây luôn)


Nếu a1 =a*1 ; a và n là số người dùng nhập vào thì ta có code sau

import java.io.*;
public class CongGiaiThua
{
	public static void main(String args[]) throws Exception
	{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		System.out.print("Nhap vao so a: ");	
		float a;
		a=Float.parseFloat(in.readLine());
		System.out.println();
		System.out.print("Nhap vao gia tri cua n(So nguyen): ");
		int n;
		n=Integer.parseInt(in.readLine());
		System.out.println();
		
		float s=1;
		float giaiThua=1;
		for(int i=1;i<=n;i++)
		{
			giaiThua = giaiThua*i; 
			if(i%2!=0)
			{
				s=s - (a*i)/giaiThua;
			}
			else
			{
				s=s+(a*i)/giaiThua;
			}
		}
		System.out.println("Gia Tri cua bieu thuc la: "+s);
	}
}

Bài viết này được chỉnh sửa bởi PhươngĐiệp2410: 06 January 2008 - 01:12 PM

<!--coloro:#008080--><!--/coloro--><!--sizeo:5--><!--/sizeo-->http://winsocks.net/

<!--sizec-->
<!--/sizec-->
<!--colorc-->
<!--/colorc--><!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->Are You looking for a good socks 5 service? But you don't know where to buy?
Welcome to WinSocks.Net - Crazy Socks Service
Here we provide Fresh Socks 5 with fast speed , less blacklist, especially price is cheaper than others service.
<!--colorc-->
<!--/colorc--><!--sizec-->
<!--/sizec--> <!--sizeo:3--><!--/sizeo--><!--coloro:#0000ff--><!--/coloro-->More over, if you want to test our socks 5 before buying, don't be hesitate to contact our supporter through yahoo to receive Free Socks 5<!--colorc--><!--/colorc--><!--sizec--><!--/sizec-->






Perfumista - Thong tin nuoc hoa

Stars Counter Game

Balloon vs. Thorns

MU Phuc Hung

Làm Việc Tài Nhà

Mu Da Nang

Tuyển Nhân Viên Bán Hàng

Tư vấn sức khỏe trực tuyến

Close [X]