Hallo leute
Ich habe ein kleines Proggi geschrieben und nun möchte ich die Button beschriften(1-4) und sie dann in 4 verschiedene Farben haben!
Ich bin noch Java Anfänger und deswegen brauche ich eure Hilfe!
Hier mein Proggi:
Danke im Vorraus
MFG
chik
Ich habe ein kleines Proggi geschrieben und nun möchte ich die Button beschriften(1-4) und sie dann in 4 verschiedene Farben haben!
Ich bin noch Java Anfänger und deswegen brauche ich eure Hilfe!
Hier mein Proggi:
Java:
package haus;
import java.awt.Color;
import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.EtchedBorder;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class fenster implements ActionListener
{
JFrame myframe = new JFrame("Fenster");
JButton mybutton [][]= new JButton [2][2];
public fenster()
{
myframe.setLocation(50,50);
myframe.getContentPane().setBackground(Color.black);
myframe.setLayout(null);
myframe.setLocationRelativeTo(null);
int heightRand = myframe.getHeight()-myframe.getContentPane().getHeight();
int widthRand = myframe.getWidth()-myframe.getContentPane().getWidth();
System.out.println("ContentPane = "+(myframe.getContentPane().getWidth())+":"+myframe.getContentPane().getHeight());
myframe.setSize(160+widthRand,170+heightRand);
myframe.setVisible(true);
myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
{
for (int i=0;i<2;i++)
{
for (int u=0;u<2;u++)
{
//System.out.println("Size of ContentPane = "+(myframe.getContentPane().getWidth())+":"+myframe.getContentPane().getHeight());
mybutton[i][u] = new JButton(" ");
mybutton[i][u].setSize(40,40);
mybutton[i][u].setLocation(i*70+20,u*60+20);
mybutton[i][u].addActionListener(this);
myframe.getContentPane().add(mybutton[i][u]);
mybutton[i][u].setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
mybutton[i][u].setVisible(true);
myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mybutton[i][u].setText("0");
}
}
}
public static void main(String[] args){
{
new fenster();{
}
}
}
@Override
public void actionPerformed(ActionEvent a)
{
System.out.println("Unser Code wird durchlaufen!!!");
buttonPressed(a.getActionCommand());
}
private void buttonPressed(String actionCommand)
{
System.out.println("Hallo!");
}
}
Danke im Vorraus
MFG
chik