Hallo
Ich möchte "selbstgemachte" farbige JPanels auf JFrames bringen, aber sie werden nicht angezeigt...
Hier die JPanels:
Hier die aufrufende Klasse:
Ich möchte "selbstgemachte" farbige JPanels auf JFrames bringen, aber sie werden nicht angezeigt...
Hier die JPanels:
Java:
import javax.swing.*;
import java.awt.*;
@SuppressWarnings("serial")
public class RGBField extends JPanel
{
int x;
int y;
int height;
int width;
Color color;
RGBField( int x, int y, int height, int width, Color color )
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.color = color;
}
@Override
protected void paintComponent( Graphics g )
{
super.paintComponent( g );
g.setColor( this.color );
g.fillRect( x, y, width, height );
g.setColor( Color.black );
g.drawRect( x, y, width, height );
}
}
Hier die aufrufende Klasse:
Java:
import java.awt.Color;
import javax.swing.JFrame;
public class Test
{
public static void main( String[] args )
{
Color redColor = new Color( 220, 230, 0 );
Color blueColor = Color.blue;
RGBField red = new RGBField( 10, 10, 100, 100, redColor );
RGBField blue = new RGBField( 120, 10, 100, 100, blueColor );
JFrame frame = new JFrame( "Test" );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setSize( 500, 500);
frame.add( red );
frame.add( blue );
frame.setVisible( true );
System.out.println( redColor.getBlue() );
}
}