Results 1 to 2 of 2
Thread: How to insert a JButton?
- 04-02-2009, 07:43 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 27
- Rep Power
- 0
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); } }
- 04-02-2009, 09:43 PM #2
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
-
How to insert large data into database using one insert query
By sandeepsai39 in forum New To JavaReplies: 3Last Post: 02-28-2009, 09:17 AM -
Insert() Method Help
By VinceGuad in forum New To JavaReplies: 7Last Post: 02-26-2009, 05:19 AM -
Help with sql insert
By jmorris in forum New To JavaReplies: 6Last Post: 12-02-2008, 07:05 PM -
SQL Insert Help!!!!
By shaungoater in forum New To JavaReplies: 1Last Post: 06-14-2008, 03:14 AM -
How do insert a Graphic
By carl in forum New To JavaReplies: 1Last Post: 08-01-2007, 05:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks