hi all bleas h need help in cods
GUI and Thread
i need help function
start ()
run()
white ()
join ()
sleep ()
setTitel ()
suspond ()
resume ()
and This class
class Thear
class track
class TestTrack
class moveTrack
class addCarrige
bleas help :) - import java.awt.*;
-
import java.awt.event.*;
-
import javax.swing.*;
-
-
-
public class MoveCar extends JFrame{
-
-
static boolean START=false;
-
static boolean Check=false;
-
static int SLEEP = 1000;
-
static int INDEX_START=0;
-
JPanel screen, area , controlroom;
-
JButton[] street , keybord;
-
String s[] = {"Start","Stop","Fast","Slow" ,"Rest","Check"};
-
-
ImageIcon images[] =new ImageIcon[] {
-
new ImageIcon("images/UpRight.jpg"),
-
new ImageIcon("images/RightDown.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
-
new ImageIcon("images/Vert.jpg"),
-
new ImageIcon("images/DownRight.jpg"),
-
new ImageIcon("images/Horiz.jpg"),
-
new ImageIcon("images/RightDown.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
-
new ImageIcon("images/Vert.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/Vert.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
-
new ImageIcon("images/Vert.jpg"),
-
new ImageIcon("images/UpRight.jpg"),
-
new ImageIcon("images/Horiz.jpg"),
-
new ImageIcon("images/RightUp.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
-
-
new ImageIcon("images/DownRight.jpg"),
-
new ImageIcon("images/RightUp.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg")
-
};
-
-
-
ImageIcon[]imagesTrain= { "images/TrainUp.jpg","images/TrainLeft.jpg","images/TrainLeft.jpg","images/TrainUp.jpg","images/TrainLeft.jpg",
-
"images/TrainLeft.jpg","images/TrainDown.jpg", "images/TrainDown.jpg","images/TrainDown.jpg","images/TrainDown.jpg",
-
"images/TrainRight.jpg","images/TrainUp.jpg","images/TrainRight.jpg","images/TrainRight.jpg","images/TrainUp.jpg"};
-
-
-
int[]line={13, 18,17,16,21,20,15,10,5,0,1,6,7,8};
-
-
ImageIcon icon;
-
-
JLabel labelInfo;
-
-
-
public MoveTrain () {
-
screen = new JPanel(new GridLayout(1,1));
-
Font f =new Font ("Sanserif",Font.BOLD,18);
-
labelInfo = new JLabel("WELCOM" ,JLabel.CENTER);
-
labelInfo.setFont(f);
-
-
screen.setBackground(Color.red);
-
screen.add(labelInfo);
-
getContentPane().add(BorderLayout.NORTH,screen );
-
-
street = new JButton[images.length];
-
area = new JPanel (new GridLayout(5,5));
-
-
for(int i=0;i<images.length;i++){
-
street[i] = new JButton("", images[i]);
-
area.add(street[i]);
-
}
-
getContentPane().add(BorderLayout.CENTER,area );
-
keybord = new JButton[6];
-
controlroom = new JPanel (new GridLayout(3,3));
-
-
for (int i=0; i <6; i++)
-
{
-
keybord[i] = new JButton(s[i]);
-
keybord[i].addActionListener(getAction(s[i]));
-
controlroom.add(keybord[i]);
-
-
}
-
getContentPane().add(BorderLayout.SOUTH,controlroom );
-
}
-
-
-
-
-
-
class moveTrain extends Thread
-
{
-
Trian t = new Train();
-
int Speed = 10;
-
t.Start();
-
int s = t.getSpeed();
-
Sleep(s);
-
}
-
void run()
-
{
-
while(true)
-
Sleep()
-
Stop
-
t.moveTrain()
-
}
-
-
-
public class TrainTest
-
public static void main(String[]args){
-
MoveCar c= new MoveCar ();
-
MoveTrain mt = new MoveTrain();
-
c.setTitle("Train");
-
c.setSize(421,550);
-
c.setVisible(true);
-
c.addWindowListener (
-
new WindowAdapter (){
-
public void windowClosing(WindowEvent e ){
-
System.exit(0);
-
}
-
});
-
mt.start();
-
}
-
}
this Link imges http://www.4shared.com/file/13555551/ff070bf/images.html
Thanks all :)
14 1846 JosAH 11,448
Recognized Expert MVP
hi all bleas h need help in cods
I'm sorry for saying so, but that code is a mess: typos and logic errors,
statements at class scope, constructors of one class defined in another class,
etc.etc. etc. Please try to compile your code, carefully read what the
compiler has to say about it, and try to fix the errors.
I can't help you out with this without rewriting the entire shebang (which I'm
not going to do). Programming is not about glueing pieces of code together.
You have to carefully organize your classes, methods and statements.
Best of luck and
kind regards,
Jos
ok sir Thanks to comment
this new code but not use Theard
i need Theard -
import java.awt.*;
-
import java.awt.event.*;
-
import javax.swing.*;
-
-
-
public class MoveCar extends JFrame{
-
-
static boolean START=false;
-
static boolean Check=false;
-
static int SLEEP = 1000;
-
static int INDEX_START=0;
-
JPanel screen, area , controlroom;
-
JButton[] street , keybord;
-
String s[] = {"Start","Stop","Fast","Slow" ,"Rest","Check"};
-
-
ImageIcon images[] =new ImageIcon[] {
-
new ImageIcon("images/UpRight.jpg"),
-
new ImageIcon("images/RightDown.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
-
new ImageIcon("images/Vert.jpg"),
-
new ImageIcon("images/DownRight.jpg"),
-
new ImageIcon("images/Horiz.jpg"),
-
new ImageIcon("images/RightDown.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
-
new ImageIcon("images/Vert.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/Vert.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
-
new ImageIcon("images/Vert.jpg"),
-
new ImageIcon("images/UpRight.jpg"),
-
new ImageIcon("images/Horiz.jpg"),
-
new ImageIcon("images/RightUp.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
-
-
new ImageIcon("images/DownRight.jpg"),
-
new ImageIcon("images/RightUp.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg")
-
};
-
-
-
-
ImageIcon[]imagesTrain=new ImageIcon[]{
-
new ImageIcon("images/TrainDown.jpg"),
-
new ImageIcon("images/TrainDown.jpg"),
-
new ImageIcon("images/TrainLeft.jpg"),
-
new ImageIcon("images/TrainLeft.jpg"),
-
new ImageIcon("images/TrainDown.jpg"),
-
new ImageIcon("images/TrainLeft.jpg"),
-
new ImageIcon("images/TrainUp.jpg"),
-
new ImageIcon("images/TrainUp.jpg"),
-
new ImageIcon("images/TrainUp.jpg"),
-
new ImageIcon("images/TrainUp.jpg"),
-
new ImageIcon("images/TrainRight.jpg"),
-
new ImageIcon("images/TrainDown.jpg"),
-
new ImageIcon("images/TrainRight.jpg"),
-
new ImageIcon("images/TrainRight.jpg")
-
};
-
-
-
-
-
-
int[]line={13, 18,17,16,21,20,15,10,5,0,1,6,7,8};
-
-
-
ImageIcon icon;
-
-
JLabel labelInfo;
-
-
-
public MoveCar () {
-
screen = new JPanel(new GridLayout(1,1));
-
Font f =new Font ("Sanserif",Font.BOLD,18);
-
labelInfo = new JLabel("WELCOM" ,JLabel.CENTER);
-
labelInfo.setFont(f);
-
-
screen.setBackground(Color.red);
-
screen.add(labelInfo);
-
getContentPane().add(BorderLayout.NORTH,screen );
-
-
street = new JButton[images.length];
-
area = new JPanel (new GridLayout(5,5));
-
-
for(int i=0;i<images.length;i++){
-
street[i] = new JButton("", images[i]);
-
area.add(street[i]);
-
}
-
getContentPane().add(BorderLayout.CENTER,area );
-
keybord = new JButton[6];
-
controlroom = new JPanel (new GridLayout(3,3));
-
for (int i=0; i <6; i++)
-
{
-
keybord[i] = new JButton(s[i]);
-
keybord[i].addActionListener(getAction(s[i]));
-
controlroom.add(keybord[i]);
-
-
}
-
getContentPane().add(BorderLayout.SOUTH,controlroom );
-
}
-
-
private ActionListener getAction(String nameAction){
-
if(nameAction.equalsIgnoreCase("Start")){ return new ActionListener(){
-
public void actionPerformed(ActionEvent e){
-
try{
-
labelInfo.setText(s[0]);
-
keybord[0].setEnabled(START);
-
START = true;
-
startTrain();
-
}catch(Exception ex){
-
ex.printStackTrace();
-
}
-
}
-
};
-
}
-
if(nameAction.equalsIgnoreCase("Stop")){ return new ActionListener(){
-
public void actionPerformed(ActionEvent e){
-
try{
-
labelInfo.setText(s[1]);
-
keybord[0].setEnabled(START);
-
START=false;
-
keybord[5].setEnabled(Check);
-
Check=false;
-
}catch(Exception ex){
-
ex.printStackTrace();
-
}
-
}
-
};
-
}
-
if(nameAction.equalsIgnoreCase("Fast")){
-
return new ActionListener(){
-
public void actionPerformed(ActionEvent e){
-
try{
-
labelInfo.setText(s[2]);
-
SLEEP=500;
-
}catch(Exception ex){
-
ex.printStackTrace();
-
}
-
}
-
};
-
}
-
if(nameAction.equalsIgnoreCase("Slow")){
-
return new ActionListener(){
-
public void actionPerformed(ActionEvent e){
-
try{
-
labelInfo.setText(s[3]);
-
SLEEP=5000;
-
}catch(Exception ex){
-
ex.printStackTrace();
-
}
-
}
-
};
-
}
-
-
-
-
return null;
-
}
-
-
-
/**
-
* @author Final Heaven
-
*/
-
public void startTrain() {
-
Thread t = new Thread(new Runnable()
-
-
{
-
public void run() {
-
for(int i=INDEX_START; START; i++){
-
street[line[(i%14)]].setIcon(imagesTrain[(i%14)]);
-
try{
-
Thread.currentThread().sleep(SLEEP);
-
}
-
catch(Exception ee){
-
ee.printStackTrace();
-
}
-
INDEX_START=i;
-
if(START)street[line[(i%14)]].setIcon(images[line[(i%14)]]);
-
-
}
-
-
}
-
-
-
});
-
t.start();
-
}
-
-
-
public static void main(String[]args){
-
MoveCar c= new MoveCar ();
-
c.setTitle("Train");
-
c.setSize(421,550);
-
c.setVisible(true);
-
c.addWindowListener (
-
new WindowAdapter (){
-
public void windowClosing(WindowEvent e ){
-
System.exit(0);
-
}
-
});
-
}
-
}
Thanks :)
ok sir Thanks to comment
this new code but not use Theard
i need Theard -
import java.awt.*;
-
import java.awt.event.*;
-
import javax.swing.*;
-
-
-
public class MoveCar extends JFrame{
-
-
static boolean START=false;
-
static boolean Check=false;
-
static int SLEEP = 1000;
-
static int INDEX_START=0;
-
JPanel screen, area , controlroom;
-
JButton[] street , keybord;
-
String s[] = {"Start","Stop","Fast","Slow" ,"Rest","Check"};
-
-
ImageIcon images[] =new ImageIcon[] {
-
new ImageIcon("images/UpRight.jpg"),
-
new ImageIcon("images/RightDown.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
-
new ImageIcon("images/Vert.jpg"),
-
new ImageIcon("images/DownRight.jpg"),
-
new ImageIcon("images/Horiz.jpg"),
-
new ImageIcon("images/RightDown.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
-
new ImageIcon("images/Vert.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/Vert.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
-
new ImageIcon("images/Vert.jpg"),
-
new ImageIcon("images/UpRight.jpg"),
-
new ImageIcon("images/Horiz.jpg"),
-
new ImageIcon("images/RightUp.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
-
-
new ImageIcon("images/DownRight.jpg"),
-
new ImageIcon("images/RightUp.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg"),
-
new ImageIcon("images/NoTrack.jpg")
-
};
-
-
-
-
ImageIcon[]imagesTrain=new ImageIcon[]{
-
new ImageIcon("images/TrainDown.jpg"),
-
new ImageIcon("images/TrainDown.jpg"),
-
new ImageIcon("images/TrainLeft.jpg"),
-
new ImageIcon("images/TrainLeft.jpg"),
-
new ImageIcon("images/TrainDown.jpg"),
-
new ImageIcon("images/TrainLeft.jpg"),
-
new ImageIcon("images/TrainUp.jpg"),
-
new ImageIcon("images/TrainUp.jpg"),
-
new ImageIcon("images/TrainUp.jpg"),
-
new ImageIcon("images/TrainUp.jpg"),
-
new ImageIcon("images/TrainRight.jpg"),
-
new ImageIcon("images/TrainDown.jpg"),
-
new ImageIcon("images/TrainRight.jpg"),
-
new ImageIcon("images/TrainRight.jpg")
-
};
-
-
-
-
-
-
int[]line={13, 18,17,16,21,20,15,10,5,0,1,6,7,8};
-
-
-
ImageIcon icon;
-
-
JLabel labelInfo;
-
-
-
public MoveCar () {
-
screen = new JPanel(new GridLayout(1,1));
-
Font f =new Font ("Sanserif",Font.BOLD,18);
-
labelInfo = new JLabel("WELCOM" ,JLabel.CENTER);
-
labelInfo.setFont(f);
-
-
screen.setBackground(Color.red);
-
screen.add(labelInfo);
-
getContentPane().add(BorderLayout.NORTH,screen );
-
-
street = new JButton[images.length];
-
area = new JPanel (new GridLayout(5,5));
-
-
for(int i=0;i<images.length;i++){
-
street[i] = new JButton("", images[i]);
-
area.add(street[i]);
-
}
-
getContentPane().add(BorderLayout.CENTER,area );
-
keybord = new JButton[6];
-
controlroom = new JPanel (new GridLayout(3,3));
-
for (int i=0; i <6; i++)
-
{
-
keybord[i] = new JButton(s[i]);
-
keybord[i].addActionListener(getAction(s[i]));
-
controlroom.add(keybord[i]);
-
-
}
-
getContentPane().add(BorderLayout.SOUTH,controlroom );
-
}
-
-
private ActionListener getAction(String nameAction){
-
if(nameAction.equalsIgnoreCase("Start")){ return new ActionListener(){
-
public void actionPerformed(ActionEvent e){
-
try{
-
labelInfo.setText(s[0]);
-
keybord[0].setEnabled(START);
-
START = true;
-
startTrain();
-
}catch(Exception ex){
-
ex.printStackTrace();
-
}
-
}
-
};
-
}
-
if(nameAction.equalsIgnoreCase("Stop")){ return new ActionListener(){
-
public void actionPerformed(ActionEvent e){
-
try{
-
labelInfo.setText(s[1]);
-
keybord[0].setEnabled(START);
-
START=false;
-
keybord[5].setEnabled(Check);
-
Check=false;
-
}catch(Exception ex){
-
ex.printStackTrace();
-
}
-
}
-
};
-
}
-
if(nameAction.equalsIgnoreCase("Fast")){
-
return new ActionListener(){
-
public void actionPerformed(ActionEvent e){
-
try{
-
labelInfo.setText(s[2]);
-
SLEEP=500;
-
}catch(Exception ex){
-
ex.printStackTrace();
-
}
-
}
-
};
-
}
-
if(nameAction.equalsIgnoreCase("Slow")){
-
return new ActionListener(){
-
public void actionPerformed(ActionEvent e){
-
try{
-
labelInfo.setText(s[3]);
-
SLEEP=5000;
-
}catch(Exception ex){
-
ex.printStackTrace();
-
}
-
}
-
};
-
}
-
-
-
-
return null;
-
}
-
-
-
/**
-
* @author Final Heaven
-
*/
-
public void startTrain() {
-
Thread t = new Thread(new Runnable()
-
-
{
-
public void run() {
-
for(int i=INDEX_START; START; i++){
-
street[line[(i%14)]].setIcon(imagesTrain[(i%14)]);
-
try{
-
Thread.currentThread().sleep(SLEEP);
-
}
-
catch(Exception ee){
-
ee.printStackTrace();
-
}
-
INDEX_START=i;
-
if(START)street[line[(i%14)]].setIcon(images[line[(i%14)]]);
-
-
}
-
-
}
-
-
-
});
-
t.start();
-
}
-
-
-
public static void main(String[]args){
-
MoveCar c= new MoveCar ();
-
c.setTitle("Train");
-
c.setSize(421,550);
-
c.setVisible(true);
-
c.addWindowListener (
-
new WindowAdapter (){
-
public void windowClosing(WindowEvent e ){
-
System.exit(0);
-
}
-
});
-
}
-
}
Thanks :)
Have you gone through a Threads tutorial yet?
Have you gone through a Threads tutorial yet?
yes more search but dont to know more Threads
Thanks :)
yes more search but dont to know more Threads
Thanks :)
Did you read the sun tutorial?
Did you read the sun tutorial?
Hi admin The Link is Error
Thanks to reply :)
Hi admin The Link is Error
Thanks to reply :)
That's funny. It was opening fine yesterday.
That's funny. It was opening fine yesterday.
very funny :)
ok admin in fine give me correct cods :)
and more Thanks
i am wait for replay :(
I'm sure if you go through a decent threads tutorial you will be able to write the codes yourself.
Jos...he's right about the link, I couldn't get it to open either.
Ra71...Here's the URL.
http://java.sun.com/docs/books/tutorial/essential/concurrency/
Thanks tedder Thanks admin r035198x
The Linke very good Tody
Thanks All :)
Thanks tedder Thanks admin r035198x
The Linke very good Tody
Thanks All :)
I edited the link yesterday. I had posted it wrong the first time.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Frithiof Andreas Jensen |
last post by:
Hi All,
I am tinkering with a stock-market analysis program that needs to have (at
least one) a worker thread for processing real-time data and a GUI where one
can control/monitor the function...
|
by: Bruce M |
last post by:
OK, IBM, why are these tools prone to hang-ups, brown screens, and
just overall inadequate performance? I've got a standard PC with 1/2
gig of memory but DB2 CC just comes-up with a big brown...
|
by: Nenad Dobrilovic |
last post by:
Hi,
I have big problem. I made generic form which can be rendered, and as a
result of that action, I get System.Windows.Forms.Form object.
Rendering must be done in GUI thread (one which has...
|
by: Flack |
last post by:
Hey guys,
I'm trying to read a file and add some nodes to a treee view control. I
would like the GUI to remain interactive and have a progress bar and text box
be updated with info as the file...
|
by: Abubakar |
last post by:
Hi,
I created 2 functions which run in seperate threads. what they do simply is
that thread1 starts and does something while the thread 2 waits for it. Then
after thread1 is done, it resumes the...
| |
by: hc0605 |
last post by:
Hi everyone,
I am a newbie to GUI application, and I need help in understanding some concepts:
For a Windows-based GUI application, the system maintains a single system message queue. Mouse...
|
by: John K Masters |
last post by:
Can someone point me in the direction of a good tutorial on programming
python with a GUI? I'm just starting out with python and have written a
few scripts successfully but would like to add a...
|
by: Kate77 |
last post by:
Hi,
I have another question,
I try to make my threads updating the form,
it works fine, for the first thread ,
but afterwards its not updating the labels on the form anymore
not from inside...
|
by: bobido |
last post by:
Hi there,
Iam trying to make an app that has about 14 different threads which have to access the GUI and update some of the labels. Now if i do that, after a little whil it kinda hangs, I think...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |