The GUI is not showing up, and when i run it from CMD it doesn't give me an error. In CMD, i type javac NewJPanel.java, then java NewJPanel and then it doesn't pop up any window.
/**
*
* #author Kevin
*/
import java.awt.*;
public class NewJPanel extends javax.swing.JPanel {
NewJPanel(){
setVisible(true);
setSize(300,400);
}
/**
* Creates new form NewJPanel
*/
public static void main(String[] args) {
new NewJPanel();
}
/**
* 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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
lblDH1 = new javax.swing.JLabel();
lblDM1 = new javax.swing.JLabel();
lblDN1 = new javax.swing.JLabel();
lblDH2 = new javax.swing.JLabel();
lblDM2 = new javax.swing.JLabel();
lblDN2 = new javax.swing.JLabel();
lblDH3 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
tfDH3 = new javax.swing.JTextArea();
jScrollPane4 = new javax.swing.JScrollPane();
tfDN2 = new javax.swing.JTextArea();
jScrollPane5 = new javax.swing.JScrollPane();
tfDM3 = new javax.swing.JTextArea();
jScrollPane6 = new javax.swing.JScrollPane();
tfDN3 = new javax.swing.JTextArea();
jScrollPane7 = new javax.swing.JScrollPane();
tfDN1 = new javax.swing.JTextArea();
jScrollPane8 = new javax.swing.JScrollPane();
tfTV1 = new javax.swing.JTextArea();
btnCalcular = new javax.swing.JButton();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jScrollPane10 = new javax.swing.JScrollPane();
jTextArea10 = new javax.swing.JTextArea();
jScrollPane11 = new javax.swing.JScrollPane();
tfTV3 = new javax.swing.JTextArea();
jScrollPane12 = new javax.swing.JScrollPane();
tfPH = new javax.swing.JTextArea();
lblDM3 = new javax.swing.JLabel();
lblDN3 = new javax.swing.JLabel();
lblTV1 = new javax.swing.JLabel();
lblTV3 = new javax.swing.JLabel();
lblPH = new javax.swing.JLabel();
jScrollPane13 = new javax.swing.JScrollPane();
tfDH1 = new javax.swing.JTextArea();
jScrollPane14 = new javax.swing.JScrollPane();
tfDM1 = new javax.swing.JTextArea();
jScrollPane15 = new javax.swing.JScrollPane();
tfDH2 = new javax.swing.JTextArea();
jScrollPane16 = new javax.swing.JScrollPane();
tfDM2 = new javax.swing.JTextArea();
lblTN = new javax.swing.JLabel();
jScrollPane19 = new javax.swing.JScrollPane();
tfTN = new javax.swing.JTextArea();
lblDH1.setText("Deportdos Hombres Vuelo #1");
lblDH1.setName("lblDH1"); // NOI18N
lblDM1.setText("Deportados Mujeres Vuelo #1");
lblDM1.setName("lblDM1"); // NOI18N
lblDN1.setText("Deportados Ninos Vuelo #1");
lblDN1.setName("lblDN1"); // NOI18N
lblDH2.setText("Deportados Hombres Vuelo #2");
lblDH2.setName("lblDH2"); // NOI18N
lblDM2.setText("Deportados Mujeres Vuelo #2");
lblDM2.setName("lblDM2"); // NOI18N
lblDN2.setText("Deportados Ninos Vuelo #2");
lblDN2.setName("lblDN2"); // NOI18N
lblDH3.setText("Deportados Hombres Vuelo #3");
jScrollPane1.setPreferredSize(new java.awt.Dimension(100, 96));
tfDH3.setColumns(20);
tfDH3.setRows(5);
jScrollPane1.setViewportView(tfDH3);
jScrollPane4.setPreferredSize(new java.awt.Dimension(100, 96));
tfDN2.setColumns(20);
tfDN2.setRows(5);
tfDN2.setName("tfDN2"); // NOI18N
jScrollPane4.setViewportView(tfDN2);
jScrollPane5.setPreferredSize(new java.awt.Dimension(100, 96));
tfDM3.setColumns(20);
tfDM3.setRows(5);
jScrollPane5.setViewportView(tfDM3);
jScrollPane6.setPreferredSize(new java.awt.Dimension(100, 96));
tfDN3.setColumns(20);
tfDN3.setRows(5);
jScrollPane6.setViewportView(tfDN3);
jScrollPane7.setPreferredSize(new java.awt.Dimension(100, 96));
tfDN1.setColumns(20);
tfDN1.setRows(5);
tfDN1.setName("tfDN1"); // NOI18N
jScrollPane7.setViewportView(tfDN1);
jScrollPane8.setPreferredSize(new java.awt.Dimension(100, 96));
tfTV1.setEditable(false);
tfTV1.setColumns(20);
tfTV1.setRows(5);
jScrollPane8.setViewportView(tfTV1);
btnCalcular.setText("Calcular");
btnCalcular.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCalcularActionPerformed(evt);
}
});
jLabel10.setText("Llegaron menos de 8 ninos en el vuelo 1");
jLabel11.setText("Llegaron menos de 8 ninos en el vuelo 2");
jLabel12.setText("Llegaron menos de 8 ninos en el vuelo 3");
jScrollPane10.setPreferredSize(new java.awt.Dimension(100, 96));
jTextArea10.setEditable(false);
jTextArea10.setColumns(20);
jTextArea10.setRows(5);
jScrollPane10.setViewportView(jTextArea10);
jScrollPane11.setPreferredSize(new java.awt.Dimension(100, 96));
tfTV3.setEditable(false);
tfTV3.setColumns(20);
tfTV3.setRows(5);
jScrollPane11.setViewportView(tfTV3);
jScrollPane12.setPreferredSize(new java.awt.Dimension(100, 96));
tfPH.setEditable(false);
tfPH.setColumns(20);
tfPH.setRows(5);
jScrollPane12.setViewportView(tfPH);
lblDM3.setText("Deportados Mujeres Vuelo #3");
lblDN3.setText("Deportados Ninos Vuelo #3");
lblTV1.setText("Total Deportados Vuelo #1");
lblTV3.setText("Total Deportados Vuelo #3");
lblPH.setText("Porcentaje de Deportados");
jScrollPane13.setPreferredSize(new java.awt.Dimension(100, 96));
tfDH1.setColumns(20);
tfDH1.setRows(5);
tfDH1.setName("tfDH1"); // NOI18N
jScrollPane13.setViewportView(tfDH1);
jScrollPane14.setPreferredSize(new java.awt.Dimension(100, 96));
tfDM1.setColumns(20);
tfDM1.setRows(5);
tfDM1.setName("tfDM1"); // NOI18N
jScrollPane14.setViewportView(tfDM1);
jScrollPane15.setPreferredSize(new java.awt.Dimension(100, 96));
tfDH2.setColumns(20);
tfDH2.setRows(5);
tfDH2.setName("tfDH1"); // NOI18N
jScrollPane15.setViewportView(tfDH2);
jScrollPane16.setPreferredSize(new java.awt.Dimension(100, 96));
tfDM2.setColumns(20);
tfDM2.setRows(5);
tfDM2.setName("tfDM2"); // NOI18N
jScrollPane16.setViewportView(tfDM2);
lblTN.setText("Grupo con Mayor Numero de Deportados");
jScrollPane19.setPreferredSize(new java.awt.Dimension(100, 96));
tfTN.setEditable(false);
tfTN.setColumns(20);
tfTN.setRows(5);
jScrollPane19.setViewportView(tfTN);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane15, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(70, 70, 70)
.addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblTN)
.addComponent(jScrollPane19, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(5, 5, 5)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel15, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel12)
.addComponent(jLabel11)
.addComponent(jLabel10)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 201, Short.MAX_VALUE)
.addComponent(btnCalcular, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(97, 97, 97))))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblDH1)
.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblDM1)
.addComponent(lblDH2)
.addComponent(lblDM2)
.addComponent(lblDN2)
.addComponent(lblDN1)
.addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane16, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane14, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(70, 70, 70)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblPH)
.addComponent(lblTV3)
.addComponent(lblTV1)
.addComponent(lblDM3)
.addComponent(jScrollPane12, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblDH3)
.addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblDN3)))
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane13, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(70, 70, 70)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 0, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jLabel15)
.addGap(112, 112, 112)
.addComponent(btnCalcular, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(88, 88, 88))
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblDH1)
.addComponent(lblDH3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane13, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblDM1)
.addComponent(lblDM3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jScrollPane14, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblDN1)
.addComponent(lblDN3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblDH2)
.addComponent(lblTV1)))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel10)
.addGap(91, 91, 91)
.addComponent(jLabel11)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel12)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblDM2)
.addComponent(lblTV3)))
.addComponent(jScrollPane15, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblDN2)
.addComponent(lblPH))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jScrollPane12, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jScrollPane16, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(6, 6, 6)
.addComponent(lblTN)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane19, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(121, Short.MAX_VALUE))
);
}// </editor-fold>
private void btnCalcularActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
btnCalcularActionPerformed(evt);
if (evt.getSource()== btnCalcular)
{
Migracion dia = new Migracion();
Vuelo vuelo1 = new Vuelo();
Vuelo vuelo2 = new Vuelo();
Vuelo vuelo3 = new Vuelo();
int a=0;
int b=0;
int c=0;
int d=0;
int e=0;
int f=0;
int g=0;
int h=0;
int i=0;
a=Integer.parseInt(tfDH1.getText());
b=Integer.parseInt(tfDM1.getText());
c=Integer.parseInt(tfDN1.getText());
d=Integer.parseInt(tfDH2.getText());
e=Integer.parseInt(tfDM2.getText());
f=Integer.parseInt(tfDN2.getText());
g=Integer.parseInt(tfDH3.getText());
h=Integer.parseInt(tfDM3.getText());
i=Integer.parseInt(tfDN3.getText());
dia.setMigra1(a, b, c);
vuelo1.setNHombres(a);
vuelo1.setNMujeres(b);
vuelo1.setNNinos(c);
dia.setMigra2(d, e, f);
vuelo2.setNHombres(d);
vuelo2.setNMujeres(e);
vuelo2.setNNinos(f);
dia.setMigra3(g, h, i);
vuelo3.setNHombres(g);
vuelo3.setNMujeres(h);
vuelo3.setNNinos(i);
int dm=0;
int dh=0;
int dn=0;
String z1;
String y;
dh=vuelo1.getNNinos();
dm=vuelo1.getNHombres();
dn=vuelo1.getNMujeres();
z1=vuelo1.total(dh, dm, dn);
y=vuelo3.total(g, h, i);
jTextArea10.setText(String.valueOf(z1));
tfTV3.setText(String.valueOf(y));
String a1="", a2="", a3="";
a1=vuelo1.advertencia(c);
a2=vuelo2.advertencia(f);
a2=vuelo3.advertencia(i);
if (a1!=" "){
jLabel10.setText("Llegaron Menos de 8 Ninos en el Vuelo 1");
}
if (a2!=" "){
jLabel11.setText("Llegaron Menos de 8 Ninos en el Vuelo 1");
}
if (a3!=" "){
jLabel12.setText("Llegaron Menos de 8 Ninos en el Vuelo 1");
}
tfPH.setText(dia.getPorcentaje());
tfTN.setText(dia.getMayoria());
}
}
// Variables declaration - do not modify
private javax.swing.JButton btnCalcular;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel15;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane10;
private javax.swing.JScrollPane jScrollPane11;
private javax.swing.JScrollPane jScrollPane12;
private javax.swing.JScrollPane jScrollPane13;
private javax.swing.JScrollPane jScrollPane14;
private javax.swing.JScrollPane jScrollPane15;
private javax.swing.JScrollPane jScrollPane16;
private javax.swing.JScrollPane jScrollPane19;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JScrollPane jScrollPane6;
private javax.swing.JScrollPane jScrollPane7;
private javax.swing.JScrollPane jScrollPane8;
private javax.swing.JTextArea jTextArea10;
private javax.swing.JLabel lblDH1;
private javax.swing.JLabel lblDH2;
private javax.swing.JLabel lblDH3;
private javax.swing.JLabel lblDM1;
private javax.swing.JLabel lblDM2;
private javax.swing.JLabel lblDM3;
private javax.swing.JLabel lblDN1;
private javax.swing.JLabel lblDN2;
private javax.swing.JLabel lblDN3;
private javax.swing.JLabel lblPH;
private javax.swing.JLabel lblTN;
private javax.swing.JLabel lblTV1;
private javax.swing.JLabel lblTV3;
private javax.swing.JTextArea tfDH1;
private javax.swing.JTextArea tfDH2;
private javax.swing.JTextArea tfDH3;
private javax.swing.JTextArea tfDM1;
private javax.swing.JTextArea tfDM2;
private javax.swing.JTextArea tfDM3;
private javax.swing.JTextArea tfDN1;
private javax.swing.JTextArea tfDN2;
private javax.swing.JTextArea tfDN3;
private javax.swing.JTextArea tfPH;
private javax.swing.JTextArea tfTN;
private javax.swing.JTextArea tfTV1;
private javax.swing.JTextArea tfTV3;
// End of variables declaration
}
I got the code from NetBeans gui builder, and pasted it into notepad++, then i added the listeners and some code. Also i deleted the package line from it.
Related
I've made a jFrame and jPanel with many buttons with the Netbeans assistant.
After hours of work, in a perfectly working code, each time I try to insert a new event, the code generated by the assistant produces hundreds of errors all around the class.
Anyone have experienced this issue?
Anyone got a fix?
Thanks.
The generated code:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package prog08notes;
/**
*
* #author Diego
*/
public class VentanaMenu extends javax.swing.JFrame {
String action = "";
String historic = "";
/**
* Creates new form VentanaMenu
*/
public VentanaMenu() {
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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPopupMenu1 = new javax.swing.JPopupMenu();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
popupMenu1 = new java.awt.PopupMenu();
jMenu3 = new javax.swing.JMenu();
jMenu4 = new javax.swing.JMenu();
jPopupMenu2 = new javax.swing.JPopupMenu();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
codAl = new javax.swing.JTextField();
inXAR = new javax.swing.JTextField();
inWEB = new javax.swing.JTextField();
inMSO = new javax.swing.JTextField();
inPROG = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
output = new javax.swing.JTextArea();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
introAs = new javax.swing.JComboBox<>();
jComboBox2 = new javax.swing.JComboBox<>();
jLabel13 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jMenu1.setText("jMenu1");
jMenu2.setText("jMenu2");
popupMenu1.setLabel("popupMenu1");
jMenu3.setText("jMenu3");
jMenu4.setText("jMenu4");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setLocationByPlatform(true);
jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jLabel1.setText("Menú de opciones");
jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jButton1.setText("1");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
jButton2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jButton2.setText("0");
jButton3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jButton3.setText("2");
jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton3MouseClicked(evt);
}
});
jButton4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jButton4.setText("3");
jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton4MouseClicked(evt);
}
});
jButton5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jButton5.setText("4");
jButton6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jButton6.setText("5");
jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jLabel2.setText("Introducir en la lista de alumnos");
jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jLabel3.setText("Visualizar la nota media del módulo");
jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jLabel4.setText("Visualizar medias de todos los alumnos");
jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jLabel5.setText("Salir");
jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jLabel6.setText("Visualizar nota determinada del alumno");
jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jLabel7.setText("Informe global del curso");
output.setEditable(false);
output.setColumns(20);
output.setRows(5);
jScrollPane1.setViewportView(output);
jLabel8.setText("COD AL");
jLabel9.setText("SiPROG");
jLabel10.setText("SiMSO");
jLabel11.setText("SiWEB");
jLabel12.setText("SiXAR");
introAs.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "SiPROG", "SiMSO", "SiWEB", "SiXAR" }));
introAs.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
introAsItemStateChanged(evt);
}
});
introAs.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
introAsActionPerformed(evt);
}
});
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jComboBox2.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jComboBox2ItemStateChanged(evt);
}
});
jLabel13.setText("SALIDA");
jTextArea1.setEditable(false);
jTextArea1.setBackground(getBackground());
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jTextArea1.setText("INSTRUCCIONES:\nIntroducir los datos (si se requieren) en las casillas \no menús correspondientes.\nPulsar el botón del menú deseado.\nLos datos se mostrarán en la ventana inferior.");
jTextArea1.setBorder(null);
jScrollPane2.setViewportView(jTextArea1);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jButton4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(35, 35, 35)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(2, 2, 2)
.addComponent(jLabel8)
.addGap(47, 47, 47)
.addComponent(jLabel9)
.addGap(44, 44, 44)
.addComponent(jLabel10)
.addGap(58, 58, 58)
.addComponent(jLabel11)
.addGap(54, 54, 54)
.addComponent(jLabel12))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(codAl, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(inPROG, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(inMSO, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(14, 14, 14)
.addComponent(inWEB, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(inXAR, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(introAs, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(312, 312, 312)))))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(35, 35, 35)
.addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGap(18, 18, 18)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(jLabel9)
.addComponent(jLabel10)
.addComponent(jLabel11)
.addComponent(jLabel12))
.addGap(10, 10, 10)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(inXAR, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(inWEB, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(inMSO, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(inPROG, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(codAl, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(introAs, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton5)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton6)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jScrollPane2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(37, 37, 37)
.addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void introAsActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jComboBox2ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
}
private void introAsItemStateChanged(java.awt.event.ItemEvent evt) {
String asignatura = (String) introAs.getSelectedItem();
if (asignatura.equals("SiPROG")) {cod = 1; };
if (asignatura.equals("SiMSO")) {cod = 2; };
if (asignatura.equals("SiWEB")) {cod = 3; };
if (asignatura.equals("SiXAR")) {cod = 4; };
}
private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {
float media = pn.mitjanaModul(cod);
writeConsole("La nota media del módulo " + introAs.getSelectedItem()+ " es " + media + ".");
}
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
//Creación de alumno
boolean check = true;
if (Alumno.validaCodi(codAl.getText())) {
try{
float f1 = Float.parseFloat(inPROG.getText());
if (!(0 <= f1 && 10 >= f1)) {check =false;};
float f2 = Float.parseFloat(inMSO.getText());
if (!(0 <= f2 && 10 >= f2)) {check =false;};
float f3 = Float.parseFloat(inWEB.getText());
if (!(0 <= f3 && 10 >= f3)) {check =false;};
float f4 = Float.parseFloat(inXAR.getText());
if (!(0 <= f4 && 10 >= f4)) {check =false;};
if (check) {
float grades []= {f1,f2,f3,f4};
pn.inserirAlumne(codAl.getText(), grades);
writeConsole("Insertado el alumno " + codAl.getText());
}
private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
}
else { writeConsole("Las notas deben estar entre 0 y 10.");};}
catch (Exception ex) {
writeConsole("Debes rellenar correctamente los campos del alumno.");
}}
else writeConsole("El código de alumno está formado por 3 mayúsculas y 2 dígitos.");
}
//Método de escritura en la consola
public void writeConsole (String s){
action = s;
historic = historic + "\n" + action;
output.setText(historic);
}
/**
* #param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(VentanaMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(VentanaMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(VentanaMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(VentanaMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new VentanaMenu().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField codAl;
private javax.swing.JTextField inMSO;
private javax.swing.JTextField inPROG;
private javax.swing.JTextField inWEB;
private javax.swing.JTextField inXAR;
private javax.swing.JComboBox<String> introAs;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JComboBox<String> jComboBox2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPopupMenu jPopupMenu1;
private javax.swing.JPopupMenu jPopupMenu2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea output;
private java.awt.PopupMenu popupMenu1;
// End of variables declaration
//Variables propias
Prog08Notes pn = new Prog08Notes();
byte cod = 1;
}
my question is very simple but I but i don't know what it is
I have a program, in java, like so
and I want to add on the JTextArea's a short message that disappeares when clicked or selected, like when you login on facebook
The JTextArea i want is for example the one below the "Startind Date:" the JTextArea is called textAreaStartindDate
this is my code so far. i used the netbeans built in design option
public class CreateEventUI extends javax.swing.JFrame {
private static final long serialVersionUID = 7526472295622776147L;
//GUARDAR EVENTOS EM REGISTOEVENTOS
/**
* Creates new form CriarEventoUI
*/
public CreateEventUI() {
super("Create an Event");
setResizable(false);
initComponents();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
}
/**
* 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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
labelChooseTypeOfEvent = new javax.swing.JLabel();
comboBoxTypeOfEvent = new javax.swing.JComboBox<>();
labelInsertTypeOfData = new javax.swing.JLabel();
labelTitle = new javax.swing.JLabel();
labelDescription = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
textAreaDescription = new javax.swing.JTextArea();
textFieldTitle = new javax.swing.JTextField();
labelStartingDate = new javax.swing.JLabel();
labelStartSubmissionDate = new javax.swing.JLabel();
labelEndDate = new javax.swing.JLabel();
labelEndSubmissionDate = new javax.swing.JLabel();
labelPlace = new javax.swing.JLabel();
textFieldPlace = new javax.swing.JTextField();
buttonConfirm = new javax.swing.JButton();
buttonCancel = new javax.swing.JButton();
textFieldStartingDate = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
labelChooseTypeOfEvent.setText("Choose the type of event");
comboBoxTypeOfEvent.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Congress" , "Exposition"}));
labelInsertTypeOfData.setText("insert the data");
labelTitle.setText("Title");
labelDescription.setText("Description");
textAreaDescription.setColumns(20);
textAreaDescription.setRows(5);
jScrollPane1.setViewportView(textAreaDescription);
labelStartingDate.setText("Starting date:");
labelStartSubmissionDate.setText("starting date for submissions:");
labelEndDate.setText("End date:");
labelEndSubmissionDate.setText("Ending date for submissions:");
labelPlace.setText("place");
buttonConfirm.setText("Confirm");
buttonConfirm.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonConfirmActionPerformed(evt);
}
});
buttonCancel.setText("Cancel");
buttonCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonCancelActionPerformed(evt);
}
});
textFieldStartingDate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
textFieldStartingDateActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelInsertTypeOfData)
.addGroup(layout.createSequentialGroup()
.addComponent(labelChooseTypeOfEvent)
.addGap(18, 18, 18)
.addComponent(comboBoxTypeOfEvent, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(labelTitle)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textFieldTitle))
.addComponent(labelDescription)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(labelPlace)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textFieldPlace)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelStartSubmissionDate)
.addComponent(labelStartingDate)
.addComponent(textFieldStartingDate, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelEndDate)
.addComponent(labelEndSubmissionDate)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(173, 173, 173)
.addComponent(buttonConfirm)
.addGap(87, 87, 87)
.addComponent(buttonCancel)))))
.addContainerGap(13, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelChooseTypeOfEvent)
.addComponent(comboBoxTypeOfEvent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(23, 23, 23)
.addComponent(labelInsertTypeOfData)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelTitle)
.addComponent(textFieldTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(labelDescription)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelStartingDate)
.addComponent(labelEndDate))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(52, 52, 52)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelStartSubmissionDate)
.addComponent(labelEndSubmissionDate))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(textFieldStartingDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelPlace)
.addComponent(textFieldPlace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonConfirm)
.addComponent(buttonCancel))
.addContainerGap(17, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void buttonConfirmActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
private void textFieldStartingDateActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
// Variables declaration - do not modify
private javax.swing.JButton buttonCancel;
private javax.swing.JButton buttonConfirm;
private javax.swing.JComboBox<String> comboBoxTypeOfEvent;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JLabel labelChooseTypeOfEvent;
private javax.swing.JLabel labelDescription;
private javax.swing.JLabel labelEndDate;
private javax.swing.JLabel labelEndSubmissionDate;
private javax.swing.JLabel labelInsertTypeOfData;
private javax.swing.JLabel labelPlace;
private javax.swing.JLabel labelStartSubmissionDate;
private javax.swing.JLabel labelStartingDate;
private javax.swing.JLabel labelTitle;
private javax.swing.JTextArea textAreaDescription;
private javax.swing.JTextField textFieldPlace;
private javax.swing.JTextField textFieldStartingDate;
private javax.swing.JTextField textFieldTitle;
// End of variables declaration
}
without using the obvious
In general you can use an ActionListener or a MouseListener.
For you did not post any code, we cannot help you out exactly. But maybe this post helps:
Onclick for TextField
Add a default text when initializing the JTextArea. Then add a FocusListener. like below:
textAreaDescription = new javax.swing.JTextArea("Description");
//jScrollPane1.setViewportView(textAreaDescription);
textAreaDescription.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
textAreaDescription.setText("");
}
public void focusLost(FocusEvent e) {
textAreaDescription.setText("Description");
}
});
Hi guys I'm currently working on a kind of "dungeon crawler" game and i need some help with saving my program. I would like for my jFrame to save(all of my entered text)so that when i close the program and open it back up from my Desktop it will have my entered text and everything i have changed still in the program. I'm confused as to how to save and am hoping for some help. Thanks ahead of time for all of your time, anwsers, links, examples, and advice. To be clear i am new to this and only have been coding for about 5 days now and i still use the Netbeans jFrame "Design" feature to generate most of the code for me. Below I've posted the code for my second Jframe. Feel free to copy and paste this code in your netbeans IDE. Thanks :).
NOTE: in case needing the names for my other Jframes.
"Character" is my second jFrame
"MainClass" is my java app
"MainGamePanel" is my third JFrame
NOTE:some buttons may not work because this is not all of my jFrames
package ddsheet; //This is the code for my jFrame named Character
import java.nio.file.Files;
import javax.swing.JFileChooser;
public class Character extends javax.swing.JFrame {
public Character() {
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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel11 = new javax.swing.JLabel();
nameValue = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
strValue = new javax.swing.JLabel();
int1Value = new javax.swing.JLabel();
dexValue = new javax.swing.JLabel();
vitValue = new javax.swing.JLabel();
hpValue = new javax.swing.JLabel();
mpValue = new javax.swing.JLabel();
stamValue = new javax.swing.JLabel();
jProgressBar1 = new javax.swing.JProgressBar();
jLabel12 = new javax.swing.JLabel();
Class = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Character"));
jLabel1.setText("Name:");
jLabel2.setText("Level:");
jLabel3.setText("Gold:");
jLabel4.setText("Str:");
jLabel5.setText("Int:");
jLabel6.setText("Dex:");
jLabel7.setText("Vit:");
jLabel8.setText("Hp:");
jLabel9.setText("Mp");
jLabel10.setText("Stam:");
jButton1.setText("Main Menu");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jLabel11.setText("Inventory");
nameValue.setText("Hiroshema");
jLabel13.setText("1");
jLabel14.setText("550");
strValue.setText("0");
int1Value.setText("0");
dexValue.setText("0");
vitValue.setText("0");
hpValue.setText("0");
mpValue.setText("0");
stamValue.setText("0");
jLabel12.setText("EXP:");
Class.setText("Class");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(35, 35, 35))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(nameValue))
.addComponent(jLabel4)
.addComponent(jLabel7)
.addComponent(jLabel9)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(int1Value, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel8)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
.addComponent(dexValue, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(strValue, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(vitValue, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(hpValue, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(mpValue, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(jLabel14))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(jLabel13)))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(stamValue, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 90, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11))
.addGap(97, 97, 97))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(Class)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel12)
.addGap(18, 18, 18)
.addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel12))
.addGap(26, 26, 26))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(Class)
.addGap(18, 18, 18)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(nameValue)
.addComponent(jLabel11))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jLabel13))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jLabel14))
.addGap(41, 41, 41)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(strValue))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(int1Value))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(dexValue))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(vitValue))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(hpValue))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(mpValue))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10)
.addComponent(stamValue))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jMenu1.setText("File");
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText("Exit");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem2.setText("Save");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem2);
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
new MainGamePanel().setVisible(true);
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
}
/**
* #param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Character.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Character.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Character.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Character.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Character().setVisible(true);
}
});
}
// Variables declaration - do not modify
public static javax.swing.JLabel Class;
public static javax.swing.JLabel dexValue;
public static javax.swing.JLabel hpValue;
public static javax.swing.JLabel int1Value;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JPanel jPanel1;
private javax.swing.JProgressBar jProgressBar1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
public static javax.swing.JLabel mpValue;
public static javax.swing.JLabel nameValue;
public static javax.swing.JLabel stamValue;
public static javax.swing.JLabel strValue;
public static javax.swing.JLabel vitValue;
// End of variables declaration
}
another idea is create a separate class containing all the information you need to save.
And use the class as an object in your main class and then save the object like this.
Look into serializing a class (this is called serialization).
public class GameState implements Serializable{
...//game settings and states stored here
}
//inside the main running class
my_settings = GameState();
...
// write object
FileOutputStream fos = new FileOutputStream(path..);
ObjectOutputStream out = new ObjectOutputStream(fos);
out.writeObject( my_settings );
out.close();
fos.close();
//read object
fis = new FileInputStream(path..);
ObjectInputStream ois = new ObjectInputStream(fis);
my_settings = (GameState) ois.readObject();
ois.close();
xml mabye?
I think you may be able to use a FileOutputStream and PrintWriter to create an xml file with data nodes keeping data of the state of everything in the game. to read it back, you might want to use Simple API for XML (SAX). Just an idea.
i am developing a java application using swing with the help of net beans. i have to open different j frame which is in different java file in another package.. with a button click.
i also want to transfer information from the current page (j frame) to the redirected j frame.
information like content of text field, radio button drop down list etc..
help me with what to write in button click action listener....
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* CriptUI.java
*
* Created on 31 Aug, 2013, 6:05:02 PM
*/
package crypt;
/**
*
* #author Nitin
*/
public class CryptUI extends javax.swing.JFrame {
/** Creates new form CriptUI */
public CryptUI() {
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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
jSpinner1 = new javax.swing.JSpinner();
jButton1 = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jPanel3 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jPanel4 = new javax.swing.JPanel();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
jMenuItem4 = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JPopupMenu.Separator();
jMenuItem5 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 628, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 28, Short.MAX_VALUE)
);
jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
jLabel1.setText("Chose Algorithm:");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jLabel2.setText("Number of itterations:");
jSpinner1.setModel(new javax.swing.SpinnerNumberModel(1, 1, 99, 1));
jButton1.setText("Encrypt Text");
jLabel3.setText("Generated soft key to decrypt:");
jLabel4.setText("Enter key:");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jComboBox1, 0, 218, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
.addComponent(jLabel3)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(45, 45, 45)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton1)
.addContainerGap())
);
jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addContainerGap(35, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
jButton2.setText("Send");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Export");
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addContainerGap(236, Short.MAX_VALUE)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addContainerGap())
);
jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton2, jButton3});
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton3)))
);
jMenu1.setText("File");
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
jMenuItem1.setText("Exit");
jMenu1.add(jMenuItem1);
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem2.setText("Cut");
jMenu2.add(jMenuItem2);
jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem3.setText("Copy");
jMenu2.add(jMenuItem3);
jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem4.setText("Paste");
jMenu2.add(jMenuItem4);
jMenu2.add(jSeparator1);
jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, 0));
jMenuItem5.setText("Delete");
jMenu2.add(jMenuItem5);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
pack();
}// </editor-fold>
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* #param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CryptUI().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.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JMenuItem jMenuItem5;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JPopupMenu.Separator jSeparator1;
private javax.swing.JSpinner jSpinner1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
}
You can do it with next code in your actionPerformed() method:
AnotherFrame f = new AnotherFrame();
f.setNeededData(/*object*/);
f.pack();
f.setVisible(true);
AnotherFrame is JFrame which you want to create and show.
setNeededData(/*object*/) is method of your frame to transfer neededData.
and last 2 lines show it.
On the click of button you can simply create the object of the JFrame which you want to open and it will load the components in it (as you must be calling initComponents() method in the default constructor).
For passing the parameters from one frame to another you can simply create a POJO and set its properties in the current frame and pass this object to the destination frame while creating the object.
I hope this helps..
On button click ActionEvent:
Create the object of class which has the frame creation function and using that object call the newFrame function :
newframe frm = new newframe(this);
frm.NewFrame();
Suppose this function is in package package org.xyz.frame;
public void NewFrame(){
JFrame frame = new JFrame("Frame2");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
try
{
for (LookAndFeelInfo info : UIManager
.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
JPanel panel = new JPanel();
frame.getContentPane().add(BorderLayout.CENTER, panel);
frame.setLocationRelativeTo(ui);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
frame.setResizable(false);
}
I'm starting to program in Java with Sql.
The problem Im having is that when I try to fill a combobox with data that I have in a table in sql, it doesn't work and I don't know why.
Here is what I have tried so far:
public class Proveedores extends javax.swing.JFrame
{
Connection cnn;
ConexionesBaseDeDatos conexiones = new ConexionesBaseDeDatos();
public Proveedores() {
initComponents();
}
#SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
txtNombreProveedor = new javax.swing.JTextField();
txtDireccionProveedor = new javax.swing.JTextField();
txtMailProveedor = new javax.swing.JTextField();
cmbProvinciasProveedores = new javax.swing.JComboBox();
btnCrearProveedor = new javax.swing.JButton();
btnModificarProveedor = new javax.swing.JButton();
btnDesabilitarProveedor = new javax.swing.JButton();
txtTelefonoProveedor = new javax.swing.JFormattedTextField();
jScrollPane1 = new javax.swing.JScrollPane();
listProveedores = new javax.swing.JList();
btnAceptar = new javax.swing.JButton();
btnGuardarCambios = new javax.swing.JButton();
btnDesabilitar = new javax.swing.JButton();
btnCancelar = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
jMenuItem4 = new javax.swing.JMenuItem();
jMenuItem5 = new javax.swing.JMenuItem();
jMenuItem6 = new javax.swing.JMenuItem();
jMenuItem7 = new javax.swing.JMenuItem();
jMenuItem10 = new javax.swing.JMenuItem();
jMenuItem11 = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
jMenuItem9 = new javax.swing.JMenuItem();
jMenu4 = new javax.swing.JMenu();
jMenuItem8 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem12 = new javax.swing.JMenuItem();
jMenu5 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
});
jLabel1.setText("Nombre");
jLabel2.setText("Teléfono");
jLabel3.setText("Dirección");
jLabel4.setText("Mail");
jLabel5.setText("Provincia");
btnCrearProveedor.setText("Crear Proveedor");
btnModificarProveedor.setText("Modificar Proveedor");
btnDesabilitarProveedor.setText("Deshabilitar Proveedor");
txtTelefonoProveedor.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
listProveedores.setEnabled(false);
listProveedores.setVisibleRowCount(13);
jScrollPane1.setViewportView(listProveedores);
btnAceptar.setText("Aceptar");
btnGuardarCambios.setText("Guardar Cambios");
btnGuardarCambios.setEnabled(false);
btnDesabilitar.setText("Desabilitar");
btnDesabilitar.setEnabled(false);
btnCancelar.setText("Cancelar");
jMenu1.setText("File");
jMenuItem1.setText("Proveedores");
jMenu1.add(jMenuItem1);
jMenuItem2.setText("Clientes");
jMenu1.add(jMenuItem2);
jMenuItem3.setText("Modelos");
jMenu1.add(jMenuItem3);
jMenuItem4.setText("Eventos");
jMenu1.add(jMenuItem4);
jMenuItem5.setText("Subastas");
jMenu1.add(jMenuItem5);
jMenuItem6.setText("Compras");
jMenu1.add(jMenuItem6);
jMenuItem7.setText("Ventas");
jMenu1.add(jMenuItem7);
jMenuItem10.setText("Colecciones");
jMenu1.add(jMenuItem10);
jMenuItem11.setText("Lineas");
jMenu1.add(jMenuItem11);
jMenu3.setText("Productos");
jMenuItem9.setText("Tipos de productos");
jMenu3.add(jMenuItem9);
jMenu1.add(jMenu3);
jMenu4.setText("Insumos");
jMenuItem8.setText("Tipos de insumos");
jMenu4.add(jMenuItem8);
jMenu1.add(jMenu4);
jMenuBar1.add(jMenu1);
jMenu2.setText("Ayuda");
jMenuItem12.setText("Acerca de...");
jMenu2.add(jMenuItem12);
jMenuBar1.add(jMenu2);
jMenu5.setText("Salir");
jMenuBar1.add(jMenu5);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(40, 40, 40)
.addComponent(btnCrearProveedor)
.addGap(97, 97, 97)
.addComponent(btnModificarProveedor)
.addGap(104, 104, 104)
.addComponent(btnDesabilitarProveedor)
.addContainerGap(64, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(67, 67, 67)
.addComponent(btnAceptar)
.addGap(52, 52, 52)
.addComponent(btnCancelar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 92, Short.MAX_VALUE)
.addComponent(btnGuardarCambios)
.addGap(62, 62, 62)
.addComponent(btnDesabilitar)
.addGap(71, 71, 71))
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(18, 18, 18)
.addComponent(cmbProvinciasProveedores, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(txtTelefonoProveedor))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel4)
.addGap(42, 42, 42)
.addComponent(txtMailProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel1))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtNombreProveedor)
.addComponent(txtDireccionProveedor, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 137, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(36, 36, 36))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnCrearProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnModificarProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(1, 1, 1)
.addComponent(btnDesabilitarProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(50, 50, 50)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtNombreProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jLabel3))
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addComponent(txtDireccionProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(3, 3, 3)
.addComponent(jLabel5))
.addComponent(cmbProvinciasProveedores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtTelefonoProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(3, 3, 3)
.addComponent(jLabel4))
.addComponent(txtMailProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(35, 35, 35))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
.addGap(27, 27, 27)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnDesabilitar)
.addComponent(btnAceptar)
.addComponent(btnCancelar)
.addComponent(btnGuardarCambios))
.addGap(64, 64, 64))
);
pack();
}// </editor-fold>
private void formWindowActivated(java.awt.event.WindowEvent evt) {
deshabilitarCampos();
if (conexiones.conectaralabase())
cargarComboProvincias();
}
public static void main()
{
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Proveedores().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnAceptar;
private javax.swing.JButton btnCancelar;
private javax.swing.JButton btnCrearProveedor;
private javax.swing.JButton btnDesabilitar;
private javax.swing.JButton btnDesabilitarProveedor;
private javax.swing.JButton btnGuardarCambios;
private javax.swing.JButton btnModificarProveedor;
private javax.swing.JComboBox cmbProvinciasProveedores;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenu jMenu5;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem10;
private javax.swing.JMenuItem jMenuItem11;
private javax.swing.JMenuItem jMenuItem12;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JMenuItem jMenuItem5;
private javax.swing.JMenuItem jMenuItem6;
private javax.swing.JMenuItem jMenuItem7;
private javax.swing.JMenuItem jMenuItem8;
private javax.swing.JMenuItem jMenuItem9;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JList listProveedores;
private javax.swing.JTextField txtDireccionProveedor;
private javax.swing.JTextField txtMailProveedor;
private javax.swing.JTextField txtNombreProveedor;
private javax.swing.JFormattedTextField txtTelefonoProveedor;
// End of variables declaration
private void deshabilitarCampos()
{
txtNombreProveedor.setEnabled(false);
txtDireccionProveedor.setEnabled(false);
txtMailProveedor.setEnabled(false);
btnAceptar.setEnabled(false);
btnCancelar.setEnabled(false);
btnDesabilitar.setEnabled(false);
btnGuardarCambios.setEnabled(false);
cmbProvinciasProveedores.setEnabled(false);
listProveedores.setEnabled(false);
}
private void habilitarCamposBtnCrearProveedor()
{
btnAceptar.setEnabled(true);
btnCancelar.setEnabled(true);
cmbProvinciasProveedores.setEnabled(true);
listProveedores.setEnabled(true);
txtDireccionProveedor.setEnabled(true);
txtMailProveedor.setEnabled(true);
txtNombreProveedor.setEnabled(true);
}
private void habilitarCamposBtnModificarProveedor()
{
btnAceptar.setEnabled(false);
btnCancelar.setEnabled(true);
cmbProvinciasProveedores.setEnabled(true);
listProveedores.setEnabled(true);
txtDireccionProveedor.setEnabled(true);
txtMailProveedor.setEnabled(true);
txtNombreProveedor.setEnabled(true);
btnGuardarCambios.setEnabled(true);
btnDesabilitarProveedor.setEnabled(false);
btnDesabilitar.setEnabled(false);
btnCrearProveedor.setEnabled(false);
}
private void limpiarCampos()
{
cmbProvinciasProveedores.setSelectedIndex(-1);
txtDireccionProveedor.setText("");
txtMailProveedor.setText("");
txtNombreProveedor.setText("");
}
public void habilitarbtnCrearProveedor()
{
btnAceptar.setEnabled(true);
btnCancelar.setEnabled(true);
cmbProvinciasProveedores.setEnabled(true);
txtDireccionProveedor.setEnabled(true);
txtMailProveedor.setEnabled(true);
txtNombreProveedor.setEnabled(true);
txtTelefonoProveedor.setEnabled(true);
}
private void cargarComboProvincias()
{
Statement sql;
ResultSet datos;
boolean seguir;
Provincias provinciaActual;
try
{
sql = cnn.createStatement();
datos = sql.executeQuery("SELECT * FROM provincias WHERE id_provincia IS NOT NULL");
seguir = datos.next();
while (seguir)
{
provinciaActual = new Provincias();
provinciaActual.setNombre_provincia(datos.getString("nombre_provincia"));
provinciaActual.toString();
cmbProvinciasProveedores.addItem(provinciaActual);
seguir = datos.next();
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage() + "error en cargarComboProvincias");
e.printStackTrace();
}
}
}
and here is where i make the connection with the database:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
public class ConexionesBaseDeDatos
{
Connection cnn;
public boolean conectaralabase()
{
String connString;
try
{
Class.forName ("com.microsoft.sqlserver.jdbc.SQLServerDriver");
connString = ("jdbc:sqlserver://GILLOPEZ:1433;database=DOLLS;Trusted_Connection=True");
cnn = DriverManager.getConnection (connString,"sa","1q2w3e4r");
}
catch(Exception e)
{
System.out.println( e.getMessage() + "Error en conectaralabase()");
return false;
}
return true;
}
}
Any help is appreciated. Thanks.
you have to three choises inside Resulset loop
1) put data to the String[] Array
`String[] items = {"test1", "test2", "test3"};
JComboBox combo = new JComboBox(items);`
2) put data to the Vector 1D Vector
Vector<String> v1 = new Vector<String>();
v1.add("item1");
v1.add("item2");
v1.add("item3");
JComboBox combo = new JComboBox(v1);
3) put data to the ComboBoxModel
DefaultComboBoxModel model = new DefaultComboBoxModel();
model.add("item1");
model.add("item2");
model.add("item3");
JComboBox combo = new JComboBox();
combo.setModel(model);
but please before anything reads
JComboBox Tutorial
JDBC Basic
tons examples here