Jeg har forgæves forsøgt at ændre min baggrundsfarve i denne frame. Det
eneste jeg kan ændre er farven hvormed tegningerne er tegnet:
import javax.swing.*;
import java.awt.*;
class Frame
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.getContentPane().add(new Panel());
frame.setTitle("Tegninger");
frame.setSize(800, 600);
frame.setVisible(true);
frame.setBackground(Color.blue);
}
}
class Panel extends JPanel
{
public void paintComponent(Graphics g)
{
//a) 4 concentric circles
g.drawOval(380,280,40,40);
g.drawOval(370,270,60,60);
g.drawOval(360,260,80,80);
g.drawOval(350,250,100,100);
//b) Transperant, 3-dimensional cube
g.drawRect(150,300,100,100);
g.drawRect(200,350,100,100);
g.drawLine(150,300,200,350);
g.drawLine(150,400,200,450);
g.drawLine(250,300,300,350);
g.drawLine(250,400,300,450);
//c) Three eggs, stacked on top of one another
g.drawOval(500,400,40,60);
g.drawOval(500,340,40,60);
g.drawOval(500,280,40,60);
//d) Snowman
g.setColor(Color.black);
g.fillRect(620,221,50,50);
g.drawLine(590,272,700,272);
g.setColor(Color.white);
g.fillOval(600,400,100,80);
g.fillOval(608,331,80,70);
g.fillOval(613,272,65,60);
}
}
Håber der er nogen som kan hjælpe
--
Mvh
Johs
|