Remove these ads by
Signing UpStep 1Build a Simple Game
import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
public class Paint extends JPanel {
@Override
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g2.setColor(Color.WHITE);
g2.fillRect(0, 0, this.getSize().width, this.getSize().height);
g2.drawImage(getBaseImage(), 235, 200,null);
g2.setColor(Color.black);
g2.drawLine(250, 215,(int)mainFrame.littleX+250, (int)mainFrame.littleY+215);
}
public BufferedImage getBaseImage(){
BufferedImage Img = null;
try {
Img = ImageIO.read(new File("/*PICTURE FILE-NAME*/"));
} catch (IOException e) {
System.err.println(e);
}
return Img;
}
//this method is optional and just adds a pic to the file
}
Create a global variable that reads-
public static javax.swing.JPanel jPanel1;
Next, on the mainFrame add the JPanel and make it the same size as the JFrame.
Set it equal to new Paint();
ie... jPanel1=new Paint();
(this code won't work quite yet so don't panic if you get a ton of errors)
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|






































