|
|
- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -
|
|
|
กระทู้ #1073 [Java] (จาก IP: 61.7.133.246)
ผุ้รู้ช่วยทีเรื่อง Thread ทำ Start/Stop
import java.awt.Color; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel;
public class a extends JFrame { int sb=0; JButton jbt = new JButton("Start/Stop"); JLabel jb[]=new JLabel[26]; a (){ for (int i=0;i<=jb.length-1;i++){ jb[i]=new JLabel(""+(char)(i+65)); jb[i].setBounds(sb+=30,10, 20, 100); jb[i].setForeground(new Color((int)(Math.random()*0xffffff))); add(jb[i]); } setSize(850, 500); setLayout(null); jbt.setBounds(350, 400, 100, 35); add(jbt); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) { a th=new a(); TestThread ta[]=new TestThread[26]; for (int i=0;i<=ta.length-1;i++){ ta[i]=new TestThread(); ta[i].init(th.jb[i],(int)(Math.random()*10)); ta[i].start(); } } } class TestThread extends Thread{ JLabel jl; int speed; int y=5; public void run(){ while(true){ try{ Thread.sleep(speed*10); if(y>350){ y=5; speed=(int)(Math.random()*10); jl.setForeground(new Color((int)(Math.random()*0xffffff))); } jl.setBounds(jl.getX(),y+=2, 20, 100); }catch(InterruptedException e){} } } public void init(JLabel jl,int sp){ this.jl=jl; speed=sp; } }
http://www.temppic.com/img.php?08-05-2007:1178569954_0.15709800.jpg
|
จากคุณ
:
abcde / aaa@aaa.com [2007-05-08 03:33:11]
|
|
ความคิดเห็น #25611 (จาก IP: 203.158.226.253)
package test;
import java.awt.Color; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.event.*;
public class a extends JFrame { int sb=0; JButton jbt = new JButton("Start/Stop"); JLabel jb[]=new JLabel[26]; TestThread ta[]; a (){
for (int i=0;i<=jb.length-1;i++){ jb[i]=new JLabel(""+(char)(i+65)); jb[i].setBounds(sb+=30,10, 20, 100); jb[i].setForeground(new Color((int)(Math.random()*0xffffff))); add(jb[i]); } setSize(850, 500); setLayout(null); jbt.setBounds(350, 400, 100, 35); add(jbt); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); a th=this; ta =new TestThread[26]; for (int i=0;i<=ta.length-1;i++){ ta[i]=new TestThread(); ta[i].init(th.jb[i],(int)(Math.random()*10)); ta[i].start(); } jbt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { for(int i=1;i<=ta.length;i++) { ta[i].stop(); } } }); } public static void main(String[] args) { new a(); } }
class TestThread extends Thread{ JLabel jl; int speed; int y=5; public void run(){ while(true){ try{ Thread.sleep(speed*10); if(y>350){ y=5; speed=(int)(Math.random()*10); jl.setForeground(new Color((int)(Math.random()*0xffffff))); } jl.setBounds(jl.getX(),y+=2, 20, 100); }catch(InterruptedException e){} } } public void init(JLabel jl,int sp){ this.jl=jl; speed=sp; } } |
จากคุณ
:
xx / winrayum@hotmail.com [2007-06-16 17:31:42]
|
|
ความคิดเห็น #25948 (จาก IP: 61.7.133.62)
อยากได้โค๊ดโปรแกรมแปลภาษาคะช่วยแนะนำด้วยนะคะ |
จากคุณ
:
พลอย / sassy_2230@hotmail.com [2007-09-06 19:04:58]
|
|
ความคิดเห็น #26103 (จาก IP: 203.146.63.184)
อยากได้โค้ด java สำหรับเช็คความเร็วอินเตอร์เน็ต
|
จากคุณ
:
เมจิ / Goodsgung@hotmail.com [2007-09-29 21:19:00]
|
|
ความคิดเห็น #27915 (จาก IP: 125.26.197.26)
อยากได้โค้ด java สำหรับเช็คความเร็วอินเตอร์เน็ต |
จากคุณ
:
เจริญ / kohhaha_4@hotmail.com [2010-06-13 15:42:20]
|
|
|
- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -
|
|
|
|
|