Results 1 to 2 of 2
Thread: Graphics
- 01-25-2008, 12:16 PM #1
Member
- Join Date
- Jan 2008
- Posts
- 21
- Rep Power
- 0
Graphics
Hey
Im trying to add some graphics to an JFrame. I have already made a jframe with loads of panels that hold seperate content. Anyway I want to add a picture, eg this smile app I riped off the net :p :-
So the class holding the above functions must extend the JFrame, fair enough, but is it possible to add this kind of content to a JPanel? Main problem I have, is that the area im drawing "things" in is a 660 x 430 space within a rather crowded window, and the size of the image may vary (its mapping software) so I dont want to start drawing over other widgets?Java Code:public TestDraw() { setLayout(new FlowLayout()); setTitle("Changing Face"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(250,220); setLocation(300,300); getContentPane().setBackground(Color.yellow); setVisible(true); } public void paint(Graphics g) { super.paint(g); g.setColor(Color.red); g.drawOval(85,75,75,75); g.setColor(Color.blue); g.drawOval(100,95,10,10); g.drawOval(135,95,10,10); g.drawArc(102,115,40,25,0,-180); g.drawString("Changing Face", 80,175); }
any pointers?
thanks
- 01-25-2008, 06:24 PM #2
This could be one of the way that you define your own JComponent for your graphics object.
Java Code:public class SmilePanel extends JComponent { public void paint(Graphics g) { super.paint(g); g.setColor(Color.red); g.drawOval(85, 75, 75, 75); g.setColor(Color.blue); g.drawOval(100, 95, 10, 10); g.drawOval(135, 95, 10, 10); g.drawArc(102, 115, 40, 25, 0, -180); g.drawString("Changing Face", 80, 175); } @Override public Dimension getPreferredSize() { Dimension dimension = new Dimension(200,200); // Change to required size return dimension; } } ... getContentPane().add(new SmilePanel());dont worry newbie, we got you covered.
Similar Threads
-
Classes in graphics
By CyberFrog in forum New To JavaReplies: 0Last Post: 04-02-2008, 09:11 PM -
graphics
By Joe2003 in forum Advanced JavaReplies: 4Last Post: 01-18-2008, 07:44 PM -
Graphics
By feniger in forum New To JavaReplies: 1Last Post: 12-29-2007, 04:22 PM -
Adding graphics to array
By romina in forum Java 2DReplies: 1Last Post: 08-01-2007, 01:45 AM -
Updating Graphics
By Greedful in forum Java 2DReplies: 2Last Post: 07-20-2007, 07:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks