How can I make a drawn shape extends with the component?
I'm drawing lines using Graphics2D. I'm starting at y = 0, but I want the
end of the line to be as maximum as frame it's contained in. So if the
user stretches the frame, I want the lines to also stretch. How can I do
that?
I include the current look of what I did:
public class DrawingApp {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater( new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
} );
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("Drawing App");
frame.setPreferredSize( new Dimension(700, 500));
frame.setLayout( new BorderLayout() );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
DrawingApp app = new DrawingApp();
GraphAreaTest area = app.new GraphAreaTest();
frame.getContentPane().add(area);
frame.pack();
frame.setVisible(true);
}
class GraphAreaTest extends Component {
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.drawLine(50, 0, 50, 100);
}
}
}
No comments:
Post a Comment