Hi All,

Im still finding it hard to understand Paint method, Almost all websites i had gone thru, they are showing examples of how to use it in an applet. I just cant understand on how to use it in a GUI application by extending Jframe object.

Here is one example, i want to create an oval shape Button to use it in my program.

Im starting my program in this way,

package painttest;

import Javax.swing.*;
import Java.awt.*

public class PaintTest extends JFrame {

private JButton oval;
private static final int HEIGHT = 400;
private static final int WIDTH = 400;

public  PaintTest(){

super("Frame");
super.setSize(WIDTH,HEIGHT);
super.setVisible(true);
super.setDefaultCloseOperation(EXIT_ON_CLOSE);
Container conInterior = super.getContentPane();
conInterior.setLayout(new GridLayout(1,1));
oval = new JButton("OvalButton");
conInterior.add(oval);
}

public static void main(String[] args) {
// TODO code application logic here

 PaintTest reference = new PaintTest();
 }

Now i understand that i will get Frame window with Rectangular button named oval.
My questions are
1. how do i use paint method in my program to make the button look like Oval Shape.
2. To change the shape of buttons is also one of the uses of Paint method, am i right?

Please advise.

Recommended Answers

All 2 Replies

You can create a new subclass of JButton, and just override its paintComponent method to paint it however you want. (Not nececssarily the best way to do that particular task, but since this is a follow-up to your earlier posts about painting in Swing, that's the most relevant general answer.)

Have a loot ak http://docs.oracle.com/javase/tutorial/uiswing/painting/

Thanks for the Suggestion...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.