Hallo, mal wieder ein zeichen problem...
Weis grad echt nicht, warum er nur die eine Komponente zeichnet und die andere nicht... er schafft es ja auch den hintergrund zu setzen, aber die paintComponent() Methode von der klasse GardenPic ruft er nicht auf.... habe mir eben auch noch ma das swing tutorial durchgelesen, aber keine ahnung wodran es liegt -.- hier der Quelltext:
[Java]
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Garden extends JApplet implements Runnable{
JButton ok;
JButton undo;
JButton close;
JTextPane textPane;
JPanel gardenPane;
JPanel btnPane;
JPanel mainPane;
GardenMap map;
GardenPic pic;
Thread draw;
AListener aListener = new AListener();
public void init() {
ok = new JButton("OK");
undo = new JButton("UNDO");
close = new JButton("CLOSE");
map = new GardenMap();
pic = new GardenPic();
textPane = new JTextPane();
gardenPane = new JPanel();
btnPane = new JPanel();
mainPane = new JPanel();
setLayout(new BorderLayout());
mainPane.setLayout(new BoxLayout(mainPane,1));
btnPane.setLayout(new BoxLayout(btnPane, 0));
gardenPane.setLayout(new GridLayout(1,5));
gardenPane.add(map);
gardenPane.add(pic);
btnPane.add(ok);
btnPane.add(undo);
btnPane.add(close);
mainPane.add(textPane);
mainPane.add(btnPane);
add(BorderLayout.CENTER, gardenPane);
add(BorderLayout.SOUTH, mainPane);
ok.addActionListener(aListener);
undo.addActionListener(aListener);
close.addActionListener(aListener);
setSize(1024,768);
setVisible(true);
}
@Override
public void start(){
if(draw == (null)){
draw = new Thread(this);
draw.start();
}
}
@Override
public void stop(){
draw.interrupt();
}
@Override
public void destroy(){
if(draw.isInterrupted()){
draw = null;
}
}
@Override
public void run() {
while(draw != null){
try{
repaint();
draw.sleep(1000);
}
catch(Exception e){
}
}
}
class AListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
String lbl = e.getActionCommand();
if(lbl.equals("OK")){
}
if(lbl.equals("UNDO")){
}
if(lbl.equals("CLOSE")){
System.exit(1);
}
}
}
class GardenMap extends JPanel{
GardenMap(){
setBackground(Color.blue);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.black);
g.drawRect(25, 25, 150, 225);
g.drawRect(50, 25, 100, 70);
g.drawLine(50, 25, 75, 60);
g.drawLine(50, 95, 75, 60);
g.drawLine(75, 60, 125, 60);
g.drawLine(125, 60, 150, 95);
g.drawLine(125, 60, 150, 25);
}
}
class GardenPic extends JPanel{
GardenPic(){
setBackground(Color.magenta);
}
public void paintComponents(Graphics g){
super.paintComponent(g);
int roofX[] = new int[]{225, 275, 325};
int roofY[] = new int[]{ 50, 15, 50};
g.setColor(Color.YELLOW);
g.fillRect(225, 50, 100, 70);
g.setColor(Color.RED);
g.fillPolygon(roofX, roofY, roofX.length);
g.setColor(Color.black);
g.drawPolygon(roofX, roofY, roofX.length);
g.drawRect(225, 50, 100, 70);
g.fillRect(235, 75, 15, 10);
g.fillRect(255, 75, 15, 10);
g.fillRect(280, 75, 15, 10);
g.fillRect(300, 75, 15, 10);
g.fillRect(265, 90, 20, 30);
}
}
}
[/Java]
Los, findet den Fehler !
Weis grad echt nicht, warum er nur die eine Komponente zeichnet und die andere nicht... er schafft es ja auch den hintergrund zu setzen, aber die paintComponent() Methode von der klasse GardenPic ruft er nicht auf.... habe mir eben auch noch ma das swing tutorial durchgelesen, aber keine ahnung wodran es liegt -.- hier der Quelltext:
[Java]
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Garden extends JApplet implements Runnable{
JButton ok;
JButton undo;
JButton close;
JTextPane textPane;
JPanel gardenPane;
JPanel btnPane;
JPanel mainPane;
GardenMap map;
GardenPic pic;
Thread draw;
AListener aListener = new AListener();
public void init() {
ok = new JButton("OK");
undo = new JButton("UNDO");
close = new JButton("CLOSE");
map = new GardenMap();
pic = new GardenPic();
textPane = new JTextPane();
gardenPane = new JPanel();
btnPane = new JPanel();
mainPane = new JPanel();
setLayout(new BorderLayout());
mainPane.setLayout(new BoxLayout(mainPane,1));
btnPane.setLayout(new BoxLayout(btnPane, 0));
gardenPane.setLayout(new GridLayout(1,5));
gardenPane.add(map);
gardenPane.add(pic);
btnPane.add(ok);
btnPane.add(undo);
btnPane.add(close);
mainPane.add(textPane);
mainPane.add(btnPane);
add(BorderLayout.CENTER, gardenPane);
add(BorderLayout.SOUTH, mainPane);
ok.addActionListener(aListener);
undo.addActionListener(aListener);
close.addActionListener(aListener);
setSize(1024,768);
setVisible(true);
}
@Override
public void start(){
if(draw == (null)){
draw = new Thread(this);
draw.start();
}
}
@Override
public void stop(){
draw.interrupt();
}
@Override
public void destroy(){
if(draw.isInterrupted()){
draw = null;
}
}
@Override
public void run() {
while(draw != null){
try{
repaint();
draw.sleep(1000);
}
catch(Exception e){
}
}
}
class AListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
String lbl = e.getActionCommand();
if(lbl.equals("OK")){
}
if(lbl.equals("UNDO")){
}
if(lbl.equals("CLOSE")){
System.exit(1);
}
}
}
class GardenMap extends JPanel{
GardenMap(){
setBackground(Color.blue);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.black);
g.drawRect(25, 25, 150, 225);
g.drawRect(50, 25, 100, 70);
g.drawLine(50, 25, 75, 60);
g.drawLine(50, 95, 75, 60);
g.drawLine(75, 60, 125, 60);
g.drawLine(125, 60, 150, 95);
g.drawLine(125, 60, 150, 25);
}
}
class GardenPic extends JPanel{
GardenPic(){
setBackground(Color.magenta);
}
public void paintComponents(Graphics g){
super.paintComponent(g);
int roofX[] = new int[]{225, 275, 325};
int roofY[] = new int[]{ 50, 15, 50};
g.setColor(Color.YELLOW);
g.fillRect(225, 50, 100, 70);
g.setColor(Color.RED);
g.fillPolygon(roofX, roofY, roofX.length);
g.setColor(Color.black);
g.drawPolygon(roofX, roofY, roofX.length);
g.drawRect(225, 50, 100, 70);
g.fillRect(235, 75, 15, 10);
g.fillRect(255, 75, 15, 10);
g.fillRect(280, 75, 15, 10);
g.fillRect(300, 75, 15, 10);
g.fillRect(265, 90, 20, 30);
}
}
}
[/Java]
Los, findet den Fehler !