G
Guest
Gast
Wie kann ich den Hintergrund meines Frames unter verwendung dieses Layouts verändern ?
Ihn durch ein Bild oder einfach durch eine Farbe ersetzen?
Ihn durch ein Bild oder einfach durch eine Farbe ersetzen?
package teste;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;
public class JButtonDemo
{
static JLabel l2=new JLabel();
public static void main( String args[] )
{
JFrame frame = new JFrame("Fenstername");
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setLayout(new GridLayout(2, 2));
JLabel l= new JLabel();
frame.setBackground(Color.green); // <------ Die Auswirkung verschwindet nach wenigen Millisekunden :(
l.setText("<html>Hey
"+"Ho</html>");
l.setHorizontalAlignment(JLabel.CENTER);
l.setVerticalAlignment(JLabel.CENTER);
l.setForeground(Color.red);
frame.add(l);
l2.setText("HeyHey");
l2.setHorizontalAlignment(JLabel.CENTER);
l2.setVerticalAlignment(JLabel.CENTER);
frame.add(l2);
JButton b = new JButton( "LEFT" );
b.setHorizontalTextPosition(JLabel.CENTER);
b.setVerticalTextPosition(JLabel.CENTER);
frame.add(b);
ActionListener al = new ActionListener() {
public void actionPerformed( ActionEvent e ) {
l2.setText("Blubb");
}
};
JButton b2 = new JButton( "RIGHT" );
b2.setHorizontalTextPosition(JLabel.CENTER);
b2.setVerticalTextPosition(JLabel.CENTER);
frame.add(b2);
ActionListener al2 = new ActionListener() {
public void actionPerformed( ActionEvent e ) {
System.exit(0);
}
};
// frame.add(l2);
b.addActionListener( al );
b2.addActionListener( al2 );
frame.setSize(500,500);
frame.setVisible( true );
}
}
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;
public class JButtonDemo
{
static JLabel l2=new JLabel();
public static void main( String args[] )
{
JFrame frame = new JFrame("Fenstername");
JPanel panel =new JPanel();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
panel.setLayout(new GridLayout(2, 2));
JLabel l= new JLabel();
panel.setBackground(Color.green); // <------ Die Auswirkung verschwindet nach wenigen Millisekunden :(
l.setText("<html>Hey
"+"Ho</html>");
l.setHorizontalAlignment(JLabel.CENTER);
l.setVerticalAlignment(JLabel.CENTER);
l.setForeground(Color.red);
panel.add(l);
l2.setText("HeyHey");
l2.setHorizontalAlignment(JLabel.CENTER);
l2.setVerticalAlignment(JLabel.CENTER);
panel.add(l2);
JButton b = new JButton( "LEFT" );
b.setHorizontalTextPosition(JLabel.CENTER);
b.setVerticalTextPosition(JLabel.CENTER);
panel.add(b);
ActionListener al = new ActionListener() {
public void actionPerformed( ActionEvent e ) {
l2.setText("Blubb");
}
};
JButton b2 = new JButton( "RIGHT" );
b2.setHorizontalTextPosition(JLabel.CENTER);
b2.setVerticalTextPosition(JLabel.CENTER);
panel.add(b2);
ActionListener al2 = new ActionListener() {
public void actionPerformed( ActionEvent e ) {
System.exit(0);
}
};
// frame.add(l2);
b.addActionListener( al );
b2.addActionListener( al2 );
frame.getContentPane().add(panel);
frame.setSize(500,500);
frame.setVisible( true );
}
}
public class JButtonDemo extends JFrame
{
private static JFrame frame = new JFrame("Fenstername");
public static void main(String[] args)
{
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setSize(500,500);
frame.setLayout(new GridLayout(10,10));
frame.setBackground(Color.green); // <------ Die Auswirkung verschwindet nach wenigen Millisekunden :(
frame.setVisible( true );
}
}
frame.getContentPane().setBackground(Color.green);
JFrame frame = new JFrame("Fenstername");
Container pane = frame.getContentPane();
pane.setBackground(Color.green);
pane.setLayout(new GridLayout(2, 2));
pane.add(....);
usw.