So I'm currently doing a project and I want to know whether or not what I'm doing is possible or not. My idea was to create 3 frames, one for each database table. I would then have a button with "Customer" and when clicked it would turn all the other frames and its components invisible while keeping it's own frame visible. Is this possible to do or is there an easier way? Is it possible to create 3 different classes for each frame and link them? I left my code below so you can get a better of what I'm trying.
public class Main extends JFrame { public Main(){ // Attach window listener addWindowListener(new WindowCloser()); // Just in-case it's needed // Adding first customer panel JPanel pCustomerL = new JPanel(); pCustomerL.setBounds(0,0,750,750); pCustomerL.setBackground(Color.BLUE); // Adding second customer panel JPanel pCustomerR = new JPanel(); pCustomerR.setBounds(750,0,750,750); pCustomerR.setBackground(Color.BLACK); // Adding first product panel JPanel pProductL = new JPanel(); pProductL.setBounds(0,0,750,750); pProductL.setBackground(Color.YELLOW); // Adding second product panel JPanel pProductR = new JPanel(); pProductR.setBounds(750,0,750,750); pProductR.setBackground(Color.GREEN); // Adding first invoice panel JPanel pInvoiceL = new JPanel(); pInvoiceL.setBounds(0,0,750,750); pInvoiceL.setBackground(Color.BLUE); // Adding second invoice panel JPanel pInvoiceR = new JPanel(); pInvoiceR.setBounds(750,0,750,750); pInvoiceR.setBackground(Color.BLACK); // Button Listener ButtonListener listener = new ButtonListener(); // Adding "Customer" Button JButton b = new JButton("Invoice"); b.addActionListener(listener); add(b); b.setBounds(1300,10,150,35); // Adding "Product" Button b = new JButton("Product"); b.addActionListener(listener); add(b); b.setBounds(1150,10,150,35); // Adding "Invoice" Button b = new JButton("Customer"); b.addActionListener(listener); add(b); b.setBounds(1000,10,150,35); // Frame Settings this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(null); this.setSize(1500,750); // Customer Panel this.add(pCustomerL); this.add(pCustomerR); // Product Panel // this.add(pProductL); // this.add(pProductR); // Invoice Panel this.add(pInvoiceL); this.add(pInvoiceR); // Customer Panel Settings pCustomerL.setVisible(false); pCustomerR.setVisible(false); // Product Settings pProductL.setVisible(true); pProductR.setVisible(true); // Invoice settings pInvoiceL.setVisible(false); pInvoiceR.setVisible(false); this.setVisible(true); } // Listener for buttons class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent evt) { String buttonLabel = evt.getActionCommand(); } } // Listener for window class WindowCloser extends WindowAdapter { public void windowClosing(WindowEvent evt) { System.exit(0);} } public static void main(String[] args) { new Main(); }
}
https://stackoverflow.com/questions/66019262/can-i-use-buttons-to-make-frames-go-between-visible-and-invisible February 03, 2021 at 07:49AM
没有评论:
发表评论