Results 1 to 2 of 2
  1. #1
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default Problem with JButton

    Hello, I'm new in java and i need some help with buttons and their actions.
    I need to insert buttons to perform three actions (draw lines).

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
     
    public class antras extends JApplet {
     
      private Rectangle2D Shape4;
     
      public antras () {
      	setBackground( Color.black );
        Shape4 = new Rectangle2D.Float (10.F, 10.F, 480.F, 280.F);
     
      }
     
      public void paint (Graphics g) {
        Graphics2D g2D;
        boolean Contained;
     
        g2D = (Graphics2D) g;
        g2D.setColor(Color.white);
        g2D.fill (Shape4);
        
        Contained = Shape4.intersectsLine (400., 10., 480., 70.);
        //first action
        g2D.setColor (Color.green);
        g2D.drawLine (10, 100, 489, 100);
        
        //second action
        g2D.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, 
                                              BasicStroke.JOIN_ROUND,
                                          1f, new float[] {2f},0f));
        g2D.setColor (Color.green);
        g2D.drawLine (10, 140, 490, 140);
        //third action 
        g2D.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, 
                                              BasicStroke.JOIN_ROUND,
                                          1f, new float[] {5f},0f));
        g2D.setColor (Color.green);
        g2D.drawLine (10, 200, 490, 200);
        
      }
    }
    Can anybody help?
    Thanks.
    Marcus:cool:
    Last edited by Marcus; 07-05-2007 at 06:54 AM.

  2. #2
    Felissa is offline Member
    Join Date
    Jun 2007
    Posts
    95
    Rep Power
    0

    Default

    What you need to look into is an Action Listener for any buttons that you implement.
    Some examples can be seen here

    I would find the examples much more useful in this case.

    Greetings.
    Felissa:p

Similar Threads

  1. JButton onClick?
    By Joe2003 in forum AWT / Swing
    Replies: 2
    Last Post: 01-06-2008, 04:04 PM
  2. Help with JButton and layout
    By adlb1300 in forum AWT / Swing
    Replies: 1
    Last Post: 12-25-2007, 09:33 AM
  3. Need help with JButton event
    By adlb1300 in forum New To Java
    Replies: 2
    Last Post: 11-19-2007, 02:15 AM
  4. mouse over on JButton
    By gradon in forum Java Applets
    Replies: 1
    Last Post: 08-04-2007, 06:50 AM
  5. Few action in one Jbutton
    By kubiasty in forum New To Java
    Replies: 0
    Last Post: 07-25-2007, 11:19 AM

Posting Permissions

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