[java][button][round]

amine -  
nerser Posted messages 39 Registration date   Status Member Last intervention   -
Hello,
how can we create a round button in Java JDK 1.3.1_01 under Windows XP?
Thank you in advance.

8 answers

nerser Posted messages 39 Registration date   Status Member Last intervention   2
 
Me neither, I have the same problem as you. If you have the answer, pass it to me.
0
besine Posted messages 20 Status Member
 
Good evening,

to give a lively look to your interfaces (XP style or others) there is a Look&fill API, for more information www.developpez.com (Java API)
0
jamel_theone Posted messages 61 Status Member 20
 
You can indeed use existing look & feel, otherwise have you tried making your own button

Something like

 public JMyButton() extends JButton { super(); this.setBorder( BorderFactory.createEmptyBorder() ); } public paint( Graphics g ) { super(g); Graphics2D g2d = (Graphics2D) g; g2d.drawEllipse( this.getX(), this.getY().... ) ..... } 


I haven't tried it but I think I would have done something like this.
0
nerser Posted messages 39 Registration date   Status Member Last intervention   2
 

I'm new to Java, but I would like you to write the code to learn, and additionally, I have a practical test tomorrow.

0
jamel_theone Posted messages 61 Status Member 20
 
The problem is that if I write the code for you, you might not learn much. What I suggest is that you try to write it yourself (using the elements I've given you) and post your code, and we'll correct it for you ;-)
0
nerser Posted messages 39 Registration date   Status Member Last intervention   2
 
```java
public class hy {
public static void main(String[] args) {
JFrame frame = new ButtonFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}

class ButtonFrame extends JFrame {
public ButtonFrame() {
setTitle("ButtonTest");
setSize(300, 200);

JButton button = new JButton("clic1 ");
JButton button1 = new JButton("clic2 ");
button1.setBorder(cercle);

JPanel p = new JPanel();
p.add(button);

public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
Ellipse2D cercle = new Ellipse2D.Double(50, 50, 50, 50);
}

Container contentPane = getContentPane();
contentPane.add(p);
}
}
```
0
jamel_theone Posted messages 61 Status Member 20
 
Voici la traduction demandée : Here is a small code that allows you to have a round button, however you still need to complete a few things (paintBorder, etc.) but generally speaking, it works like this

 import java.awt.*; import javax.swing.*; public class RoundButton extends JButton { public RoundButton (String label) { super(label); this.setContentAreaFilled(false); } protected void paintComponent(Graphics g) { g.setColor(getBackground()); g.fillOval(0, 0, this.getSize().width-1, this.getSize().height-1); super.paintComponent(g); } public static void main(String[] args) { JFrame frame = new JFrame(); JButton button = new RoundButton ("Button"); button.setBackground(Color.BLUE); frame.getContentPane().add(button); frame.setSize(200, 200); frame.setVisible(true); } } 
0
nerser Posted messages 39 Registration date   Status Member Last intervention   2
 
Thank you Jamel for your help, I would like to get to know you.
Here is my email derder_athmane@hotmail.com
0