Til _carsten
I forlængelse af tidligere besvaret spg. har jeg nu forsøgt at sætte din kode ind i mit program som jeg er ved at bygge op. Jeg må overse en lille fejl, for det virker i det kode eks. som jeg satte op i det tidligere spg., men når jeg lægger det ind imit rigtige program, sker der ikke noget når jeg trykker på knappen.Kan du "spotte" fejlen
Klasse1 Jframe
//*********Skal flyttes over i vores rigtige main klasse senere*******
import javax.swing.UIManager;
//********************************************************************
public class GUI_Hovedmenu extends javax.swing.JFrame {
/** Creates new form GUI_Hovedmenu */
public GUI_Hovedmenu() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
hovedmenuVenstre = new javax.swing.JPanel();
logo = new javax.swing.JLabel();
hovedmenuTop = new javax.swing.JPanel();
admTestbesvarelse = new javax.swing.JButton();
admItem = new javax.swing.JButton();
eksport = new javax.swing.JButton();
visHer = new javax.swing.JPanel();
aft = new GUI_AdmAfTestbesvarelser(); <--------INDSAT KODE
getContentPane().setLayout(null);
setTitle("MCA");
setBackground(new java.awt.Color(221, 221, 221));
setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
setLocationRelativeTo(null);
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
hovedmenuVenstre.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
hovedmenuVenstre.setBackground(new java.awt.Color(64, 128, 128));
hovedmenuVenstre.setBorder(new javax.swing.border.EtchedBorder());
hovedmenuVenstre.setForeground(new java.awt.Color(64, 128, 128));
logo.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\Kim Eriksen\\Dokumenter\\MMI Java\\Mlogo.jpg"));
logo.setText("jLabel1");
logo.setDisabledIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\Kim Eriksen\\Dokumenter\\MMI Java\\Mlogo.jpg"));
hovedmenuVenstre.add(logo, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 510, 80, 110));
getContentPane().add(hovedmenuVenstre);
hovedmenuVenstre.setBounds(0, 0, 140, 680);
hovedmenuTop.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
hovedmenuTop.setBackground(new java.awt.Color(221, 221, 221));
hovedmenuTop.setBorder(new javax.swing.border.EtchedBorder());
hovedmenuTop.setDoubleBuffered(false);
admTestbesvarelse.setText("<html><center>Administration<br>af testbesvarelser</center></html>");
hovedmenuTop.add(admTestbesvarelse, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 10, 140, -1));
admItem.setText("<html><center>Administration<br>af items</center></html>");
hovedmenuTop.add(admItem, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 10, 140, -1));
eksport.setText("Eksport");
eksport.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
eksportActionPerformed(evt);
}
});
hovedmenuTop.add(eksport, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 10, 140, 40));
getContentPane().add(hovedmenuTop);
hovedmenuTop.setBounds(140, 0, 800, 60);
visHer.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
getContentPane().add(visHer);
visHer.setBounds(140, 60, 790, 580);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-940)/2, (screenSize.height-680)/2, 940, 680);
}
private void eksportActionPerformed(java.awt.event.ActionEvent evt) {
visHer.add(aft); <--------INDSAT KODE
visHer.validate(); <--------INDSAT KODE
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
//*********Skal flyttes over i vores rigtige main klasse senere*******
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
e.printStackTrace();
}
//********************************************************************
new GUI_Hovedmenu().show();
}
// Variables declaration - do not modify
private javax.swing.JButton admItem;
private javax.swing.JButton admTestbesvarelse;
private javax.swing.JButton eksport;
private javax.swing.JPanel hovedmenuTop;
private javax.swing.JPanel hovedmenuVenstre;
private javax.swing.JLabel logo;
private javax.swing.JPanel visHer;
// End of variables declaration
private GUI_AdmAfTestbesvarelser aft; <--------INDSAT KODE
-----------------------------------------------------
Klasse2 Jpanel
public class GUI_AdmAfTestbesvarelser extends javax.swing.JPanel {
/** Creates new form GUI_AdmAfTestbesvarelser */
public GUI_AdmAfTestbesvarelser() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
nyTestbesvarelse = new javax.swing.JButton();
RedigeringAfTestbesvarelse = new javax.swing.JButton();
setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
nyTestbesvarelse.setText("<html><center>Opret ny<br> testbesvarelse</center></html>");
add(nyTestbesvarelse, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 20, 140, -1));
RedigeringAfTestbesvarelse.setText("<html><center>Redigering af<br> testbesvarelse</center></html>");
add(RedigeringAfTestbesvarelse, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 240, 140, -1));
}
// Variables declaration - do not modify
private javax.swing.JButton RedigeringAfTestbesvarelse;
private javax.swing.JButton nyTestbesvarelse;
// End of variables declaration
}