Results 1 to 2 of 2
  1. #1
    aRTx is offline Member
    Join Date
    Mar 2009
    Posts
    27
    Rep Power
    0

    Question How to insert a JButton?

    Hi,

    In chich method do I need to write code to add a JButton ?


    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.geom.*;
    
    public class Ex2 extends JApplet {
      public static void main(String s[]) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JApplet applet = new Ex2();
        applet.init();
        frame.getContentPane().add(applet);
        frame.pack();
        frame.setVisible(true);
      }
      
      public void init() {
        JPanel panel = new Ex2Panel();
        getContentPane().add(panel);
      }
    }
    
    class Ex2Panel extends JPanel{          
      public Ex2Panel() {
        setPreferredSize(new Dimension(400, 400));
        setBackground(Color.white);
      }
    
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        int w = this.getWidth();
        int h = this.getHeight();
        int r = Math.min(w, h) - 100;
        Area a = new Area(new Rectangle(r, r));
        a.subtract(new Area(new Ellipse2D.Double(r/4, r/4, r/2, r/2)));
        g2.translate((w-r)/2, (h-r)/2);
        g2.setColor(Color.green);
        g2.fill(a);
        g2.setColor(Color.black);
        g2.draw(a);
      }
    }

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    please explain what this code does and what you want to do. do you want the button to show up in both the applet and the application? or just one of them?
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. Replies: 3
    Last Post: 02-28-2009, 09:17 AM
  2. Insert() Method Help
    By VinceGuad in forum New To Java
    Replies: 7
    Last Post: 02-26-2009, 05:19 AM
  3. Help with sql insert
    By jmorris in forum New To Java
    Replies: 6
    Last Post: 12-02-2008, 07:05 PM
  4. SQL Insert Help!!!!
    By shaungoater in forum New To Java
    Replies: 1
    Last Post: 06-14-2008, 03:14 AM
  5. How do insert a Graphic
    By carl in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 05:30 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
  •