In my head it works like this.
bounds.width:
Code:
___________________________
| |
| *bounds.width* |
| <--------------------------------> |
| |
|__________________________|
bounds.height:
Code:
___________________________
| ^ |
| | |
| | bonds.height |
|__________\/_______________|
so bounds is the integer value of the distance.
So the insets must be the coordinates?
_______________________________________
Code:
class sTart
extends JPanel {
private Image image;
private int imageHeight;
private int imageWidth;
public sTart(ImageIcon img) {
if(img != null) {
image = img.getImage();
imageWidth = image.getWidth(this);
imageHeight = image.getHeight(this);
if(imageWidth > 0 && imageHeight > 0) {
setPreferredSize(new Dimension(imageWidth, imageHeight));
}
}
}
public sTart() {
setBorder(BorderFactory.createLineBorder(Color.black));
}
public Dimension getPreferredSize() {
return new Dimension(500, 350);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Insets insets = getInsets();
int width = insets.left;
int dX1 = 0;
int dY1 = 0;
int dX2 = 0;
int dY2 = 0;
int sX1 = 0;
int sY1 = 0;
int sX2 = 0;
int sY2 = 0;
g.drawImage(image,
dX1,
dY1,
dX2,
dY2,
sX1,
sY1,
sX2,
sY2,
this);
g.drawImage(image, 0, 0, 0, 0, 0, 0, 200, 200, this);
g.drawString(String.valueOf(width) + String.valueOf(insets.right) + String.valueOf(insets.bottom), 10, 20);
}
}
___________[______________________________________________
Code:
import javax.imageio.ImageIO;
import java.io.File;
import java.awt.Frame;
import javax.swing.JFrame;
import java.io.IOException;
import java.awt.*;
import javax.swing.*;
import java.awt.image.ImageObserver;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import java.io.IOException;
public class machine
extends JPanel {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
start();
}
}
);
}
private static void start() {
JFrame surge = new JFrame("SuRgE!");
surge.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon menu = new ImageIcon("database//StartMenu.jpg");
surge.add(new sTart(menu));
surge.pack();
surge.setVisible(true);
}
}
why doesn't this display the StartMenu.jpg? If it is because I am using the drawImage incorrectly disreguard this question.