Posted By:
Derk_Dukker
Posted On:
Friday, May 6, 2005 02:24 PM
Hello I have some problems with JPanels I Have an application, when you click a button he opens a class DatabasePaneel extends JPanel. In that class I want to make a go back button to the previous screen (the main application) but how can I maken that??? below is the source code of the 2 classes package kaleidoscope; import java.awt.*; import javax.swing.*; import java.awt.event.*; /** * Title: Kaleidoscope Ordersysteem * * Description: Ordersysteem * * Copyright: Copyright (c) 2005 * * Company: Projectgroep RDA * * @author Remko Hendrikse, Arnout de Jonker en Derk
More>>
Hello I have some problems with JPanels
I Have an application, when you click a button he opens a class DatabasePaneel extends JPanel.
In that class I want to make a go back button to the previous screen (the main application) but how can I maken that???
below is the source code of the 2 classes
package kaleidoscope;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
*
Title: Kaleidoscope Ordersysteem
*
*
Description: Ordersysteem
*
*
Copyright: Copyright (c) 2005
*
*
Company: Projectgroep RDA
*
* @author Remko Hendrikse, Arnout de Jonker en Derk Dukker
* @version 0.1
*/
public class Kaleidoscope extends JFrame {
JPanel contentPane, pnButton;
//private DatumPaneel datumPaneel; //het implementeren van de datumpaneel interface
DatabasePaneel pnDatabase; // het implementeren van de databasePaneel
AdministratiePaneel pnAdministratie; //het implementeren van de pnAdministratie
OrderPaneel pnOrder; //het implementeren van de orderPaneel
PlanningPaneel pnPlanning;//het implementeren van de pnPlanning
JButton btOrderInvoerPaneel, btPlanningPaneel, btAdministratiePaneel, btDatabase;
private JLabel lbTitel;//, statusbar;
FlowLayout flowLayout;
GridBagLayout gridBagLayout;
GridBagConstraints constraints;
/**
* Construct and show the application.
*/
public Kaleidoscope() {
FlowLayout flowLayout = new FlowLayout();
GridBagLayout gridBagLayout = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
contentPane = new JPanel(flowLayout);
pnButton = new JPanel(gridBagLayout);
//datumPaneel = new DatumPaneel( "Voer datum in: " );
pnDatabase = new DatabasePaneel("Voer Database gegevens in: ");
pnAdministratie = new AdministratiePaneel("Administratie");
pnOrder = new OrderPaneel("Orderadministratie");
pnPlanning = new PlanningPaneel("Planning");
btOrderInvoerPaneel = new JButton("Order invoer");
btOrderInvoerPaneel.addActionListener(new OrderInvoerKnopHandler());
btPlanningPaneel = new JButton("Planning");
btPlanningPaneel.addActionListener(new PlanningKnopHandler());
btAdministratiePaneel = new JButton("Administratie");
btAdministratiePaneel.addActionListener(new AdministratieKnopHandler());
btDatabase = new JButton("database");
btDatabase.addActionListener(new DatabaseKnopHandler());
Component strut50 = Box.createVerticalStrut(50);
lbTitel = new JLabel("Kaleidoscope - Ordersysteem");
lbTitel.setFont(new Font("Dialog", Font.BOLD, 15));
//statusbar = new JLabel("status: ");
int top = 2; //extra ruimte aan de bovenkant
int left = 2; //extra ruimte aan de linkerkant
int bottom = 2; //extra ruimte aan de onderkant
int right = 2; //extra ruimte aan de rechterkant
constraints.insets = new Insets(top, left, bottom, right); //voeg de extra ruimtes toe
constraints.gridwidth = GridBagConstraints.REMAINDER; //betekent einde van de row
constraints.fill = GridBagConstraints.BOTH; //btpen even hoog en breed
pnButton.add(lbTitel, constraints);
pnButton.add(strut50, constraints);
pnButton.add(btOrderInvoerPaneel, constraints);
pnButton.add(btPlanningPaneel, constraints);
pnButton.add(btAdministratiePaneel, constraints);
pnButton.add(btDatabase, constraints);
contentPane.add(pnButton); //pnButton toevoegen aan de contentPane
setContentPane(contentPane);
}
class AdministratieKnopHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
contentPane.removeAll();
contentPane.add(pnAdministratie);
setContentPane(contentPane);
}
}
class OrderInvoerKnopHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
contentPane.removeAll();
contentPane.add(pnOrder);
setContentPane(contentPane);
}
}
class PlanningKnopHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
contentPane.removeAll();
contentPane.add(pnPlanning);
setContentPane(contentPane);
}
}
class DatabaseKnopHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
contentPane.removeAll();
contentPane.add(pnDatabase);
setContentPane(contentPane);
}
}
public static void main(String[] args) {
JFrame frame = new Kaleidoscope();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize( 800, 900 );
frame.setTitle( "Kaleidoscope - Ordersysteem BETA 0.1" );
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.setVisible( true );
Thread splashThread = new Thread(new SplashScreen());
splashThread.start();
}
}
the Panel class
package kaleidoscope;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
/**
*
Title: Kaleidoscope Ordersysteem
*
*
Description: Ordersysteem
*
*
Copyright: Copyright (c) 2005
*
*
Company: Projectgroep RDA
*
* @author Remko Hendrikse, Arnout de Jonker en Derk Dukker
* @version 0.1
*/
public class AdministratiePaneel extends JFrame {
Kaleidoscope kaleidoscope;
DatabasePaneel pnDatabase;
JButton btKlantenAdmin, btProductenAdmin, btPapiersoortAdmin, btTerug,
btPalletsoortAdmin, btSnijmaatAdmin, btDiameterAdmin, btDoosFormaatAdmin, btDatabaseAdmin ;
JLabel lbAdministratie, test;
JPanel pnButton, pnBasis;
//Container container;
FlowLayout flowLayout;
GridBagLayout gridBagLayout;
GridBagConstraints constraints;
public AdministratiePaneel(String omschrijving) {
//Container container = getContentPane();
flowLayout = new FlowLayout();
pnBasis = new JPanel(flowLayout);
pnDatabase = new DatabasePaneel("Database gegevens");
//this.setLayout(flowLayout);
GridBagLayout gridBagLayout = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
pnButton = new JPanel(gridBagLayout);
int top = 2; //extra ruimte aan de bovenkant
int left = 2; //extra ruimte aan de linkerkant
int bottom = 2; //extra ruimte aan de onderkant
int right = 2; //extra ruimte aan de rechterkant
constraints.insets = new Insets(top, left, bottom, right); //voeg de extra ruimtes toe
constraints.gridwidth = GridBagConstraints.REMAINDER; //betekent einde van de row
constraints.fill = GridBagConstraints.BOTH; //knoppen even hoog en breed
btKlantenAdmin = new JButton("Klanten administratie");
btProductenAdmin = new JButton("Productenadministratie");
btPapiersoortAdmin = new JButton("Papiersoorten administratie");
btPalletsoortAdmin = new JButton("Palletsoorten administratie");
btSnijmaatAdmin = new JButton("Snijmaat administratie");
btDiameterAdmin = new JButton("Diameters administratie");
btDoosFormaatAdmin = new JButton("Doosformaat administratie");
btDatabaseAdmin = new JButton("Database verbindinggegevens");
btDatabaseAdmin.addActionListener(new DatabaseKnopHandler());
btTerug = new JButton("Terug naar hoofdmenu");
btTerug.addActionListener(new TerugKnopHandler());
constraints.insets = new Insets(top, left, bottom, right); //voeg de extra ruimtes toe
constraints.gridwidth = GridBagConstraints.REMAINDER; //betekent einde van de row
constraints.fill = GridBagConstraints.BOTH; //knoppen even hoog en breed
lbAdministratie = new JLabel("Adminstratie");
lbAdministratie.setFont(new Font("Dialog", Font.BOLD, 15));
lbAdministratie.setVerticalTextPosition(JLabel.CENTER);
lbAdministratie.setHorizontalTextPosition(JLabel.CENTER);
test = new JLabel();
Component strut50 = Box.createVerticalStrut(50);
pnButton.add(lbAdministratie, constraints);
pnButton.add(strut50, constraints);
pnButton.add(btDoosFormaatAdmin, constraints);
pnButton.add(btKlantenAdmin, constraints);
pnButton.add(btProductenAdmin, constraints);
pnButton.add(btPapiersoortAdmin, constraints);
pnButton.add(btPalletsoortAdmin, constraints);
pnButton.add(btSnijmaatAdmin, constraints);
pnButton.add(btDiameterAdmin, constraints);
pnButton.add(btDatabaseAdmin, constraints);
pnButton.add(test, constraints);
pnBasis.add(pnButton);
add(pnDatabase).setVisible(false);
add(pnBasis);
add(btTerug, constraints);
}
class DatabaseKnopHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
pnBasis.removeAll();
pnDatabase.setVisible(true);
}
}
class TerugKnopHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
//return to the main screen kaleidoscope.java
}
}
}
<<Less