import java.awt.*;
import javax.swing.*;
public class StretchyGraphics extends JPanel {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
int w = getWidth();
int h = getHeight();
g2.drawRect(w/16, h/16, w*7/8, h*7/8);
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new StretchyGraphics());
f.setSize(400,400);
f.setVisible(true);
}
}