title: java graphic bugs when called from another class
body: <p>I am writing a program, on which I just simply write, edit and show some short entries. So far, everything is working just fine and I was pretty much done, but for some reason now the Gui starts messing with me. Meaning, at the beginning everything is normal, but when I am e.g. trying to switch back from the second Gui to the first, it will still show the button, graphics etc. of the second Gui. Strangly, when I am making the changes directly at the main file and not at the other class, it works just fine - even though I think icalled everything correctly, I just bothers me and I cannot figure out the reason. Thank you very much for any help I can get!</p>
  
  <p>Here are some code snippets:</p>
  
  <p>JFrame:</p>
  
  <pre><code>package main;
  
  public class JFD3 extends JFrame {
  
  private static final long serialVersionUID = 1L;
  private JPanel contentPane;
  int Gui=1;
  public JTextField txtFilter;
  public JButton btnNewEntry;
  public JScrollPane spDefault;
  public JTextArea txtDefault;
  public JScrollPane spEntry;
  public JButton btnBack;
  public JButton btnEdit;
  public JTextArea txtEntry;
  public static boolean entry=true;
  public static File cEntry;
  public JButton btnSave;
  public JTextField txtTitle;
  
  public static void main(String[] args) {
      EventQueue.invokeLater(new Runnable() {
          public void run() {
              try {
                  JFD3 frame = new JFD3();
                  frame.setVisible(true);
                  frame.setIconImage(Toolkit.getDefaultToolkit().getImage("C:/Users/Admin/workspace/JFD3/files/icon/icon.jpeg"));
                  frame.setTitle("JavaFunctionsDatabase3");
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      });
  }
  
  public JFD3() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setBounds(100, 100, 450, 300);
      contentPane = new JPanel();
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
      contentPane.setLayout(null);
  
      spDefault = new JScrollPane();
      spDefault.setBounds(12, 66, 225, 174);
      contentPane.add(spDefault);
      txtDefault = new JTextArea();
      txtDefault.addMouseListener(new MouseAdapter() {
          public void mouseClicked(MouseEvent arg0) {
              int line=0;
              try {
                   line = txtDefault.getLineOfOffset(txtDefault.getCaretPosition());
              } catch (BadLocationException e) {
                  e.printStackTrace();
              }
              ShowEntry showentry = new ShowEntry();
              try {
                  showentry.ProveLine(line, txtFilter);
              } catch (IOException e) {
                  e.printStackTrace();
              }
              if(entry==true){
                  Gui=2;
                  repaint();
              }
          }
      });
      txtDefault.setFont(new Font("Tahoma", Font.PLAIN, 20));
      spDefault.setViewportView(txtDefault);
      txtDefault.setEditable(false);
  
      txtFilter = new JTextField();
      txtFilter.addKeyListener(new KeyAdapter() {
          public void keyPressed(KeyEvent arg0) {
              repaint();
          }
      });
      txtFilter.setFont(new Font("Tahoma", Font.PLAIN, 18));
      txtFilter.setBounds(249, 153, 168, 41);
      contentPane.add(txtFilter);
      txtFilter.setColumns(10);
  
      btnNewEntry = new JButton("New Entry");
      btnNewEntry.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
              Gui=4;
              repaint();
          }
      });
      btnNewEntry.setFont(new Font("Tahoma", Font.PLAIN, 18));
      btnNewEntry.setBounds(249, 66, 168, 41);
      contentPane.add(btnNewEntry);
      btnNewEntry.setFocusable(false);
      btnNewEntry.setBackground(Color.GRAY);
  
      JPanel panel = new JPanel(){
          private static final long serialVersionUID = 1L;
          public void paint(Graphics g){
              try {
                  CreateGui(g);
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      };
      panel.setBounds(0, 0, 432, 262);
      contentPane.add(panel);
  
      spEntry = new JScrollPane();
      spEntry.setBounds(12, 66, 225, 174);
      contentPane.add(spEntry);
      txtEntry = new JTextArea();
      txtEntry.setFont(new Font("Tahoma", Font.PLAIN, 16));
      txtEntry.setEditable(false);
      spEntry.setViewportView(txtEntry);
      spEntry.setVisible(false);
  
      btnEdit = new JButton("Edit Entry");
      btnEdit.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              Gui=3;
              repaint();
          }
      });
      btnEdit.setFont(new Font("Tahoma", Font.PLAIN, 18));
      btnEdit.setBounds(249, 66, 168, 41);
      contentPane.add(btnEdit);
      btnEdit.setBackground(Color.GRAY);
      btnEdit.setVisible(false);
      btnEdit.setFocusable(false);
  
      btnBack = new JButton("Back");
      btnBack.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
              if(Gui==2||Gui==4){
                  Gui=1;
                  txtEntry.setText("");
                  txtTitle.setText("");
                  repaint();
              }else{
                  Gui=2;
                  repaint();
              }
          }
      });
      btnBack.setFont(new Font("Tahoma", Font.PLAIN, 18));
      btnBack.setBounds(249, 116, 168, 41);
      contentPane.add(btnBack);
      btnBack.setVisible(false);
      btnBack.setBackground(Color.GRAY);
      btnBack.setFocusable(false);
  
      btnSave = new JButton("Save Entry");
      btnSave.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
              if(Gui==3){
                  try {
                      EditEntry editentry = new EditEntry();
                      editentry.SaveEntry(txtEntry, txtTitle);
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
                  Gui=2;
                  repaint();
              }else{
                  if(!txtEntry.getText().equals("")&amp;&amp;!txtTitle.getText().equals("")){
                      try {
                          NewEntry newentry = new NewEntry();
                          newentry.SaveEntry(txtTitle, txtEntry);
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
                      txtEntry.setText("");
                      txtTitle.setText("");
                      Gui=1;
                      repaint();
                  }
              }
          }
      });
      btnSave.setFont(new Font("Tahoma", Font.PLAIN, 18));
      btnSave.setBounds(249, 66, 168, 41);
      contentPane.add(btnSave);
      btnSave.setFocusable(false);
      btnSave.setVisible(false);
      btnSave.setBackground(Color.GRAY);
  
      txtTitle = new JTextField();
      txtTitle.setBounds(12, 15, 225, 35);
      txtTitle.setFont(new Font("Tahoma", Font.PLAIN, 32));
      contentPane.add(txtTitle);
      txtTitle.setColumns(10);
      txtTitle.setVisible(false);
  }
  
  public void CreateGui(Graphics g) throws IOException{
      if(Gui==1){
          Default default1 = new Default();
          default1.CreateGui(g, spDefault, txtFilter, btnNewEntry, txtDefault, spEntry, btnEdit, btnBack, txtTitle, txtEntry);
      }
      if(Gui==2){
          ShowEntry showentry = new ShowEntry();
          showentry.CreateGui(g, spDefault, txtFilter, btnNewEntry, txtDefault, spEntry, btnEdit, btnBack, txtEntry, txtTitle);
          showentry.FillEntry(txtEntry);
      }
      if(Gui==3){
          EditEntry editentry = new EditEntry();
          editentry.CreateGui(txtEntry, btnEdit, btnSave, txtTitle);
      }
      if(Gui==4){
          NewEntry newentry = new NewEntry();
          newentry.CreateGui(btnSave, btnBack, txtTitle, txtEntry, spDefault, spEntry, btnNewEntry, txtFilter);
      }
  }
  }
  </code></pre>
  
  <p>the default class which should change the gui</p>
  
  <pre><code>  package main;
  
  public class Default extends JFD3{
  
  private static final long serialVersionUID = 1L;
  File[] L = F.listFiles();
  boolean filter=true;
  
  public void CreateGui(Graphics g, JScrollPane spDefault, JTextField txtFilter, JButton btnNewEntry, JTextArea txtDefault, JScrollPane spEntry, JButton btnEdit, JButton btnBack, JTextField txtTitle, JTextArea txtEntry) throws IOException{
      spDefault.setVisible(true);
      txtFilter.setVisible(true);
      btnNewEntry.setVisible(true);
      spEntry.setVisible(false);
      btnBack.setVisible(false);
      btnEdit.setVisible(false);
      txtEntry.setEditable(false);
      txtTitle.setVisible(false);
      g.setFont(new Font("Tahoma", Font.PLAIN, 32));
      g.drawString("JavaFunctionsDatabase3", 15, 45);
      g.setFont(new Font("Tahoma", Font.PLAIN, 20));
      g.drawString("Filter", 249, 145);
      ShowEntries(txtDefault, txtFilter);
  }
  </code></pre>