public class Main0 extends JFrame{
public Main0(){
super("Księżyc");
this.setBounds(100,100,500,500);
init();
this.setDefaultCloseOperation(3);
}
public void init(){
panel3.add(wspol);
panel2.setLayout(new GridLayout(6, 6));
for(int i=0; i<6; i++)
for(int j=0; j<6; j++)
b_buttony();
// panel2.addMouseListener(new myszka());
panel.add(obszar);
panel.add(text);
b_button("KONWERTUJ");
this.getContentPane().add(panel, BorderLayout.PAGE_START);
this.getContentPane().add(panel2, BorderLayout.CENTER);
this.getContentPane().add(panel3, BorderLayout.PAGE_END);
pack();
}
public void b_button(String nazwa){
JButton przycisk = new JButton(nazwa);
przycisk.addActionListener(new sluchacz());
panel.add(przycisk);
}
public void b_buttony(){
JButton przycisk2 = new JButton();
przycisk2.addMouseListener(new myszka());
panel2.add(przycisk2);
}
private class myszka extends MouseAdapter{
public void mouseEntered(MouseEvent e) {
((b_buttony())e.getSource()).getText();
}
}
private class sluchacz implements ActionListener{
@Override
public void actionPerformed(ActionEvent e){
// String odczyt = text.getText();
obszar.setText(""+Integer.parseInt(text.getText())*2);
}
}
public static void main(String[] args){
new Main0().setVisible(true);
}
private JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
private JPanel panel2 = new JPanel();
private JPanel panel3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
private JTextField text = new JTextField(4);
private JTextArea obszar = new JTextArea(1,4);
private JTextArea wspol = new JTextArea(1,8);
}
Napisałem taką aplikacje. Mam pytanie, jak zrobić, żeby po najechaniu myszką na buttona zmienić jego kolor na Color.RED?