2

I am trying to draw bar and dot graphs in a JTabbedPane for an app I am making. I did some research and it seems other people are using the paintComponent(Graphics g) function to paint on all the visuals. However, I am not sure how to implement this function as a part of try{ from ActionListener. So when a button is clicked, a new Frame will appear for the Graphs.

JButton btnGraphs = new JButton("Graphs");
    add(btnGraphs, "cell 1 5,alignx center");
    btnGraphs.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {




            } catch (Exception e) {

            }
        }
    });
Jonik
  • 80,077
  • 70
  • 264
  • 372
Kevin
  • 31
  • 2

1 Answers1

0

simpliest way would be to design your application to fit MVC (Model-View-Control)...

your actionListener (control) would modifies the data (model) and after that the actionListener would tell the Gui (View) to be drawn.

once you appeal to this design pattern it makes no difference if you draw a new frame or force your existing component to be re-drawn...

see https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

Martin Frank
  • 3,445
  • 1
  • 27
  • 47