Ich habe diese Klasse erstellt, die ein JFrame mit einem Hintergrundbild erstellen. Ich versuche, auf diesem Bild einen Kreis zu zeichnen. Aber ich kann nur das Bild oder die Figur zeigen, der Kreis wird nicht auf dem Bild angezeigt. Ich rufe die Klasse von meiner Hauptstelle an.So malen Sie auf JFrame
Sorry, wenn dies ia newbie Frage :)
package worldofzuul;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
/**
*
* @author JesperJørgensen
*/
public class GraphicsFrame extends JFrame {
private JPanel man = new JPanel();
void setupframe() {
// Here we create the Frame
JFrame frame = new JFrame(); // create the frame
frame.setLayout(new BorderLayout());
frame.setResizable(false);
frame.setTitle("Zuul the ultimate fridaybar game"); // sets title in top bar of frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // what will happens when the frame close (exit)
//Here we set the background image (the map which we walk in)
ImageIcon icon = new ImageIcon("src/Image/Kort.png");
frame.add(new JLabel(icon));
frame.setContentPane(new DrawPane());
frame.pack(); // sets the size of the frame to fit all objects inside.
frame.setVisible(true); // show the frame
}
class DrawPane extends JPanel {
@Override
protected void paintComponent(Graphics g) {
g.setColor(Color.red);
g.fillRect(20, 20, 100, 200);
}
}
}
Vielen Dank :) es funktioniert perfekt! – yspede
Ich bin froh, dass es hilft. Siehe http://stackoverflow.com/help/someone-answers – c0der