Results 1 to 6 of 6
Thread: Help with this java applet
- 03-08-2010, 05:01 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 2
- Rep Power
- 0
Help with this java applet
import java.applet.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;
import javax.swing.*;
public class ButtonApplet extends Applet {
public ButtonApplet()
{
JPanel panel= new JPanel();
panel.add(makeButton("left", -Xx, 0));
panel.add(makeButton("right", Yy, 0));
panel.add(makeButton("UP",0, -Yy));
panel.add(makeButton("down", 0, Xx));
JFrame frame = new JFrame();
frame.setContentPane(panel);
frame.pack();
frame.show();
}
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
g2.drawOval(Xx,Yy,100,100);
g2.translate(x, y);
//repaint();
}
public JButton makeButton(String label, final double rr3, final double rr2)
{
JButton button = new JButton(label);
class ButtonListener implements ActionListener
{public void actionPerformed(ActionEvent event)
{
repaint();
}
}
ButtonListener listener = new ButtonListener();
button.addActionListener(listener);
return button;
}
static String r = JOptionPane.showInputDialog("Please input a radius");
static double Rr = Double.parseDouble(r);
private static int x = 100;
private static int y = 100;
private static int Xx = (int) (x - Rr);
private static int Yy = (int) (y - Rr);
}
this is the code i have its suposed to draw a circle and when u click the buttons move the circle left right up or down and i cant seem to figure out where my error is if u can help plz do thanks in advance
- 03-08-2010, 09:44 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
The code you have is mostly wrong. I can't tell if it should be a Swing applet or an AWT applet since you are unsuccessfully combining techniques from both. I suggest learn how to write a Swing applet.
Start by reading the section from the Swing tutorial on "How to Make Applets". Also in the tutorial is a section on custom painting that might help.
And don't forget to use the "Code" tags when posting code.
- 03-09-2010, 01:56 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes, you code has lots of errors. As camickr says my suggestion too is the use of swing, rather AWT. But at the same time AWT is much easy to use.
Checkout the following simple code
Java Code:import java.applet.*; import java.awt.*; public class MyCircle extends Applet{ public void paint(Graphics g){ g.drawOval(250,50,100,100); } }
- 03-09-2010, 01:58 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Read the following before dig into the applets.
How to Make Applets (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
- 03-09-2010, 02:50 AM #5
Member
- Join Date
- Mar 2010
- Posts
- 2
- Rep Power
- 0
thank u guys very much im a high school senior in a basic computer programing class and was told to try and make a program that did this well i tried and my teacher told me i had some small error in my code but couldnt find it he would look more tomarrow after he spent 20 mins looking it over well aparently he is stupid and didnt know wat he was talking about as there is lots of errors thank u for ur help u are all very nice :D
- 03-14-2010, 11:53 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
you are welcome.
If you've solved the problem please mark thread solved from the tools menu.
Similar Threads
-
Help with this Java applet !!!!!
By danielmessick in forum Java AppletsReplies: 2Last Post: 03-07-2010, 12:58 PM -
How do i fix this Java applet ??????
By danielmessick in forum JCreatorReplies: 1Last Post: 03-07-2010, 12:55 PM -
What're the differences between JSP, Java Script, and Java Applet?
By meili100 in forum New To JavaReplies: 3Last Post: 07-23-2008, 08:07 AM -
New to JAVA Applet
By kazitula in forum Java AppletsReplies: 2Last Post: 10-31-2007, 08:11 PM -
Java 3d in applet
By carl in forum Java AppletsReplies: 1Last Post: 08-06-2007, 05:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks