Ich möchte 2 Dinge:ausblenden JButton nach Klick auf das
- ausblenden meine Taste „PLAY“, nachdem ich darauf klicken.
Um weitere Tasten an den gleichen Positionen zu verlassen, in dem sie waren, bevor ich die PLAY-Taste
public class MusicPlayer { public static void main (String[] args) { JFrame frame = new JFrame("Main window"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(600, 400)); frame.setResizable(false); frame.setVisible(true); frame.pack(); frame.setLayout(new BorderLayout()); JPanel panel = new JPanel(new GridBagLayout()); JButton b1 = new JButton("PLAY"); JButton b2 = new JButton("PAUSE"); JButton b3 = new JButton("STOP"); GridBagConstraints layout = new GridBagConstraints(); layout.insets = new Insets(0, 10, 5, 0); layout.anchor = GridBagConstraints.SOUTH; layout.weighty = 1; panel.add(b1, layout); panel.add(b2, layout); panel.add(b3, layout); frame.add(panel, BorderLayout.CENTER); panel.setBackground(Color.blue); b1.setBackground(Color.green); b2.setBackground(Color.yellow); b3.setBackground(Color.red); } }
nicht 'setVisible (falsch);' Arbeit? –
Ich habe versucht, es wie folgt in Funktion zu setzen: b1.addActionListener (new Graj()); \t statische Klasse Graj implementiert Action { \t \t public void actionPerformed (Action e) { \t \t} \t \t \t \t public void hideButton (Action e, JButton b) { \t \t \t b.setVisible (false); \t \t} \t} – wuwunio94
hinzufügen actionlistner zum Posten. –