This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

adding controls to JFrame  RSS feed

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is my program the controls are not getting added please advise me how to add it.


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

//<applet code=testing width=600 height=400></applet>
public class testing extends JFrame implements Runnable //, WindowListener
{
Thread t;
int i, j, x, y;
public volatile boolean run=true;

JButton b1, b2;

public static void main(String args[])
{
testing tst=new testing();
}

public testing()
{
b1=new JButton("stop");
b2=new JButton("start");
JPanel p=new JPanel();
//setBackground(Color.pink);
p.add(b1);
p.add(b2);
pack();
setVisible(true);
setSize(800, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//b1.addActionListener(this);
//b2.addActionListener(this);
//addWindowListener(new winadapt());
t=new Thread(this);
t.start();
}

/*public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
try{
t.sleep(10000);
}catch(InterruptedException e1){}
}
if (e.getSource()==b2)
{
t=new Thread(this);
t.start();
}
}*/


public void run()
{
for(i=0;i<210;i+=10)
{
repaint();
try
{
t.sleep(300);
}catch (InterruptedException es)
{}

}


}
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.drawLine(50, 250, 50+i, 250);
g.drawLine(50, 50, 50, 50+i);
}


}
 
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't post the same question to multiple forums; it leads to duplicated effort. Let's continue the discusssion in the applet forum, where there is an answer to your question already.
[ January 09, 2006: Message edited by: Ulf Dittmer ]
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!