Jing Liang

Ranch Hand
+ Follow
since Oct 23, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Jing Liang

Sorry forgot to wrap it with CODE on the first post.

18 years ago
In my JApplet, I am able to change the background color of the panel but not the currentSurface which is an instance of PaintSurface. Could someone please help me out? Many thanks

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

public class Tanks extends JApplet
{
public static final int WIDTH = 400;
public static final int HEIGHT = 400;
private JButton button1;
private PaintSurface currentSurface = new PaintSurface();

public Tanks()
{
this.add(currentSurface,BorderLayout.CENTER);
ButtonListener b1 = new ButtonListener();
JPanel panel = new JPanel();
panel.setBackground(Color.white);
currentSurface.setBackground(Color.white);

button1 = new JButton("Start");
button1.addActionListener(b1);
panel.add(button1);
this.add(panel,BorderLayout.NORTH);

}


public void init()
{
this.setSize(WIDTH, HEIGHT);

this.setVisible(true);


}


private class ButtonListener implements ActionListener
{


public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand() == "Start")
{
currentSurface.figure="Start";
repaint();
}
}


}
}


class AnimationThread extends Thread
{
JApplet c;

public AnimationThread(JApplet c)
{
this.c = c;
}

public void run()
{

}
}


class PaintSurface extends JComponent
{
String figure;


public PaintSurface()
{

}

public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;

g2.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);



if(figure=="Start")
{
Shape s = new Ellipse2D.Float(20,50,250,150);
g2.setPaint(Color.BLACK);
g2.draw(s);

}


}
}
18 years ago
How do I draw(show) the ellipse only if the start button is pressed?
Thanks in advance

18 years ago
The button shows up when I add the button at the init() BorderLayout.NORTH
18 years ago
It works. Thanks Eric
18 years ago
My codes able to draw the ellipse but not the button("Start"). I added the button to the JComponent. Could someone tell me what I did wrong and help me out? Thanks in advance

18 years ago
Thank you very much
18 years ago
I have question when to create an object.
Examples:
when we use the Math methods, we write Math.random(), Math.pow()

So why we need to create an instance when we use the Scanner methods


How do I know when to create an instance or not?

Thanks in advance
18 years ago
Problem solved thanks guys
18 years ago
Hello guys,

I couldn't fix this NPE. Please Help. Thanks
In my playGame() method, I have

I receive NPE from t.start();

Here are my program
18 years ago
Thanks Michael
18 years ago
Thanks Ernest

The javax.swing.Timer will call my method at every interval time but I only want it delay the time to call my method once. Do you know how could I fix this?
18 years ago
Hi guys,

I am looking for a method or class that can delay calling my method at a defined interval. Does anyone have an idea? Thanks
18 years ago
I don't want Box to be inner class, so how can call on boxes[i][j] and set its showColor variables from the picked() method? thanks
18 years ago