jbutton

Only 1 Corner is Rounded when I call fillRoundRect()

自古美人都是妖i 提交于 2020-06-27 15:31:07
问题 When run this code: import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import javax.swing.JButton; import javax.swing.JLabel; public class CustomButton extends JButton { int width = 100; int height = 50; int radius = 10; JLabel lab; @Override protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.ORANGE); g2

ActionListener and Thread.sleep

风格不统一 提交于 2020-03-12 05:44:46
问题 I have a JButton, which, as soon as I click on it, I want to change some colors after a few seconds, for example from blue -> 1 sec -> red -> 1 sec -> yellow. My problem is that, as soon as I use the Thread.sleep function in ActionListener and I test my program, it freezes for the 2 seconds and gives me directly yellow. How can I fix that? Thanks a lot 回答1: ActionListener and Thread.sleep.. ..don't play well together. Don't block the EDT (Event Dispatch Thread) - the GUI will 'freeze' when

ActionListener and Thread.sleep

ぐ巨炮叔叔 提交于 2020-03-12 05:44:27
问题 I have a JButton, which, as soon as I click on it, I want to change some colors after a few seconds, for example from blue -> 1 sec -> red -> 1 sec -> yellow. My problem is that, as soon as I use the Thread.sleep function in ActionListener and I test my program, it freezes for the 2 seconds and gives me directly yellow. How can I fix that? Thanks a lot 回答1: ActionListener and Thread.sleep.. ..don't play well together. Don't block the EDT (Event Dispatch Thread) - the GUI will 'freeze' when

JButton background image

假如想象 提交于 2020-01-31 05:39:11
问题 Hi i am trying to implement Action listener for JButton and code look like following: ImageIcon imageForOne = new ImageIcon(getClass().getResource("resources//one.png")); one = new JButton("",imageForOne); one.setPreferredSize( new Dimension(78, 76)); one.addActionListener(myButtonHandler); Using the above JButton it looks fine When i add specific value to button for e.g. ImageIcon imageForOne = new ImageIcon(getClass().getResource("resources//one.png")); //Check this one = new JButton("one"

How to remove a JButton in a JButton matrix?

故事扮演 提交于 2020-01-25 14:16:55
问题 I want to remove a certain botton using MouseListener from a matrix of bottons and add a JLabel in the empty, so I use: import java.awt.*; import java.awt.event.*; import javax.swing.*; public MyClass(){ object = new Object(); bottons = new JButton[5][5]; labels = new JLabel[5][5]; myPanel = new JPanel(); myPanel.setLayout(new GridLayout(5,5)); click =false; for(int i = 0 ; i<5 ; i++){ for(int j = 0; j<5 ; j++){ myPanel.add(bottons[i][j] = new JButton()); } } } public void mouseReleased

How to remove a JButton in a JButton matrix?

十年热恋 提交于 2020-01-25 14:15:10
问题 I want to remove a certain botton using MouseListener from a matrix of bottons and add a JLabel in the empty, so I use: import java.awt.*; import java.awt.event.*; import javax.swing.*; public MyClass(){ object = new Object(); bottons = new JButton[5][5]; labels = new JLabel[5][5]; myPanel = new JPanel(); myPanel.setLayout(new GridLayout(5,5)); click =false; for(int i = 0 ; i<5 ; i++){ for(int j = 0; j<5 ; j++){ myPanel.add(bottons[i][j] = new JButton()); } } } public void mouseReleased

How to remove a JButton in a JButton matrix?

风流意气都作罢 提交于 2020-01-25 14:13:23
问题 I want to remove a certain botton using MouseListener from a matrix of bottons and add a JLabel in the empty, so I use: import java.awt.*; import java.awt.event.*; import javax.swing.*; public MyClass(){ object = new Object(); bottons = new JButton[5][5]; labels = new JLabel[5][5]; myPanel = new JPanel(); myPanel.setLayout(new GridLayout(5,5)); click =false; for(int i = 0 ; i<5 ; i++){ for(int j = 0; j<5 ; j++){ myPanel.add(bottons[i][j] = new JButton()); } } } public void mouseReleased

How to remove a JButton in a JButton matrix?

一世执手 提交于 2020-01-25 14:13:18
问题 I want to remove a certain botton using MouseListener from a matrix of bottons and add a JLabel in the empty, so I use: import java.awt.*; import java.awt.event.*; import javax.swing.*; public MyClass(){ object = new Object(); bottons = new JButton[5][5]; labels = new JLabel[5][5]; myPanel = new JPanel(); myPanel.setLayout(new GridLayout(5,5)); click =false; for(int i = 0 ; i<5 ; i++){ for(int j = 0; j<5 ; j++){ myPanel.add(bottons[i][j] = new JButton()); } } } public void mouseReleased

No J components show on my shape?

喜欢而已 提交于 2020-01-25 03:41:12
问题 I'm having a really big issue in which when ether I create a JLabel, Jbutton and so on....it works in terms of showing on screen however when I want to place them on a rectangle it disappears and the rectangle only shows? With JLabel I opted to use drawstring instead but now I'm stuck with trying to get JTextField on. I don't know what I am missing. import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.lang.*; import javax.swing.event.*; class main { public static void

Java no sound played for button

僤鯓⒐⒋嵵緔 提交于 2020-01-24 09:13:50
问题 I have created a class to play the sound when I click the buttons. Here is the code : public void playSound() { try { AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("beep-1.wav")); Clip clip = AudioSystem.getClip( ); clip.open(audioInputStream); clip.start( ); } catch(Exception e) { System.out.println("Error with playing sound."); } } When I want to implement it into the the ButtonListener method, it's seem like no sound is played. Here the ButtonListener code :