You could use the Graphics2D.scale() method, which scales the entire graphics transform or you can just add a scale multiplier to all of the dimensions of your drawn objects. You'll probably want to use a float for the scaling factor.
I'd also recommend using a JPanel and overriding paintComponent() for your drawing. Painting directly to the JFrame with getGraphics() is too transient. You'll lose your graphics any time the system needs to re-render a portion of the window, such as resizing, etc.
Ezzaral
null
16,111 posts since May 2007
Reputation Points: 3,292
Solved Threads: 873
Skill Endorsements: 28
that about how to LayoutManagers works, for example
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestResizeFrame extends JFrame {
private static final long serialVersionUID = 0;
static final int INNER_WIDTH = 320;
static final int INNER_HEIGHT = 320;
private OvalPanel panel = new OvalPanel();
private class OvalPanel extends JPanel {
private static final long serialVersionUID = 0;
@Override
public void paintComponent(Graphics g) {
g.setColor(Color.red);
g.drawOval(0, 0, this.getWidth(), this.getHeight());
}
}
public TestResizeFrame() {
panel.setPreferredSize(new Dimension(INNER_WIDTH, INNER_HEIGHT));
add(panel, BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new TestResizeFrame().setVisible(true);
}
});
}
}
mKorbel
Nearly a Posting Virtuoso
1,215 posts since Feb 2011
Reputation Points: 482
Solved Threads: 239
Skill Endorsements: 12