I'm trying to make x and y axis of a graph that can automatically resize when the window size is changingThis is my code, I'm trying to use addComponentlistener to help resize the axis but it doesn't work. I guess it have to do with graphics g is inside another anonymous class, but I'm not sure how to fix it. (I'm noob)
display = new JPanel(){
@Override
public void paintComponent(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;
addComponentListener(new ComponentAdapter(){
public void componentResized(ComponentEvent e){
Component c = (Component)e.getSource();
int x1 = c.getWidth()/8;
int y1 = c.getHeight()/4;
int x2 = c.getWidth()*7/8;
int y2 = c.getHeight()/4;
g.drawLine(10,100,100,100 );
}});
}
};