8 answers
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)
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)
You can indeed use existing look & feel, otherwise have you tried making your own button
Something like
I haven't tried it but I think I would have done something like this.
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.
I'm new to Java, but I would like you to write the code to learn, and additionally, I have a practical test tomorrow.
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 ;-)
```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);
}
}
```
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);
}
}
```
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); } }