Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Default 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

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    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.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    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);
      }
    }

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  5. #5
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Default

    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

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Help with this Java applet !!!!!
    By danielmessick in forum Java Applets
    Replies: 2
    Last Post: 03-07-2010, 01:58 PM
  2. How do i fix this Java applet ??????
    By danielmessick in forum JCreator
    Replies: 1
    Last Post: 03-07-2010, 01:55 PM
  3. Replies: 3
    Last Post: 07-23-2008, 09:07 AM
  4. New to JAVA Applet
    By kazitula in forum Java Applets
    Replies: 2
    Last Post: 10-31-2007, 09:11 PM
  5. Java 3d in applet
    By carl in forum Java Applets
    Replies: 1
    Last Post: 08-06-2007, 06:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •