Originariamente inviato da LeleFT
1) Impara a scrivere il codice e a non usare editor visuali: sei alle prime armi e quelle sono "armi improprie" anche per chi è già skilled.
2) Come hai scritto la tua classe "MiaFinestra"? Come la estendi?
Ciao.
La classe mia finestra l'ho fatta fare dal rad, comunque se può servire è questa :
codice:
package gui;
public class InizioProgramma extends javax.swing.JFrame {
/** Creates new form InizioProgramma */
public InizioProgramma() {
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.
*/
@SuppressWarnings("unchecked")
private void initComponents() {
jToolBar1 = new javax.swing.JToolBar();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jSeparator2 = new javax.swing.JToolBar.Separator();
jButton3 = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JPopupMenu.Separator();
jMenuItem3 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jToolBar1.setFloatable(false);
jToolBar1.setRollover(true);
jToolBar1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jToolBar1.setFocusable(false);
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/exit32.png"))); // NOI18N
jButton1.setToolTipText("Esci dal Programma");
jButton1.setFocusable(false);
jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jToolBar1.add(jButton1);
jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/options.png"))); // NOI18N
jButton2.setToolTipText("Opzioni");
jButton2.setFocusable(false);
jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jToolBar1.add(jButton2);
jToolBar1.add(jSeparator2);
jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/information.png"))); // NOI18N
jButton3.setToolTipText("Informazioni sul programma");
jButton3.setFocusable(false);
jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jToolBar1.add(jButton3);
jMenu1.setText("File");
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.ALT_MASK));
jMenuItem1.setText("Opzioni");
jMenu1.add(jMenuItem1);
jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
jMenuItem2.setText("Uscita");
jMenu1.add(jMenuItem2);
jMenu1.add(jSeparator1);
jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.ALT_MASK));
jMenuItem3.setText("Informazioni");
jMenu1.add(jMenuItem3);
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, Short.MAX_VALUE)
.addGap(263, 263, 263))
);
pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
Option opt = new Option(this,true);
opt.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new InizioProgramma().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JPopupMenu.Separator jSeparator1;
private javax.swing.JToolBar.Separator jSeparator2;
private javax.swing.JToolBar jToolBar1;
// End of variables declaration
}
dopo di che ho semplicemente fatto un altro jframe e invece di fargli estendere jframe gli ho fatto estendere la mia classe, così:
codice:
package etichettecabler;
/**
*
* @author POSTOSW2
*/
public class mainFrame extends gui.InizioProgramma {
/** Creates new form NewJFrame */
public mainFrame() {
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.
*/
@SuppressWarnings("unchecked")
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new mainFrame().setVisible(true);
}
});
}
per il resto non sono proprio alle prime armi con java, sono ancora noob perchè c'è sempre da imparare
solo che non ho mai avuto il bisogno di fare una base "grafica" comune, l'ho sempre creata dal rad, anche se per codice sarei abbastanza capace eprchè è molto piu comodo e veloce
ho bisogno che questa classe si veda graficamente dal rad per poter aggiungere su quella finestra degli swing in base al programma che devo fare
una precisazione : se la faccio andare funziona, nel senso, ho il risultato che mi aspetto, il problema sta proprio nel modificarlo dato rad.
edit: Non mi ha formattato bene il codice ora lo modifico