Hi i am trying to print in a Jdialog the values of a selected row from the main frame .
i m trying this ,but when i call the method("m.SetRecoger) in the main frame it´s showing this error :
"method SetRecoger in class Modificar cannot be applied to given types;
required: String[]
found: no arguments
reason: actual and formal argument lists differ in length"
the complete code :
the main frame where i have the jtable:
public class DniFrame extends javax.swing.JFrame {
/**
* Creates new form DniFrame
*/
public DniFrame() {
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();
jScrollPane2 = new javax.swing.JScrollPane();
jTable2 = new javax.swing.JTable();
jButton1 = 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();
jMenuItem4 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
jTable2.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Nif", "Nom", "Cognoms", "Telefon"
}
));
jScrollPane2.setViewportView(jTable2);
jButton1.setText("Actualizar Datos");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
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)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jMenu1.setText("Aplicació");
jMenuItem1.setText("Sortir");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuBar1.add(jMenu1);
jMenu2.setText("Base de Dades");
jMenu2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenu2ActionPerformed(evt);
}
});
jMenuItem2.setText("Afegir");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem2);
jMenuItem4.setText("Modificar");
jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem4ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem4);
jMenuItem3.setText("Eliminar");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem3);
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)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, 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.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
new afegir(this, true).setVisible(true);
}
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {
modify();
Modificar m=new Modificar(this, true);
m.SetRecoger();
new Modificar(this, true).setVisible(true);
}
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel modelo = (DefaultTableModel) this.jTable2.getModel();
int i = jTable2.getSelectedRow();
if (i == -1) {
JOptionPane.showMessageDialog(null, "Debes selecioonar una fila");
} else {
int ax = JOptionPane.showConfirmDialog(null, "Estás seguro de que quieres eliminar este registro?");
if (ax == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(null, "Has seleccionado SI.");
String dni = (String) jTable2.getValueAt(i, 0);
modelo.removeRow(jTable2.getSelectedRow());
try {
Class.forName("com.mysql.jdbc.Driver");
try (Connection conexion = DriverManager.getConnection("jdbc:mysql://192.168.100.128/mibase", "asis", "titanic24")) {
Statement comando = conexion.createStatement();
comando.executeUpdate("delete from dades_pers where nif = '" + dni + "'");
}
JOptionPane.showMessageDialog(null, "Registro borrado");
} catch (ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, "No se ha podido eliminar el registro");
} catch (SQLException ex) {
Logger.getLogger(DniFrame.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (ax == JOptionPane.NO_OPTION) {
JOptionPane.showMessageDialog(null, "Has seleccionado NO.");
}
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conexion = DriverManager.getConnection("jdbc:mysql://192.168.100.128/mibase", "asis", "titanic24");
Statement comando = conexion.createStatement();
ResultSet result = comando.executeQuery("select * from dades_pers");
ResultSetMetaData rsMD = result.getMetaData();
int numcolumnas = rsMD.getColumnCount();
DefaultTableModel modelo = new DefaultTableModel();
this.jTable2.setModel(modelo);
for (int x = 1; x <= numcolumnas; x++) {
modelo.addColumn(rsMD.getColumnLabel(x));
}
while (result.next()) {
Object[] fila = new Object[numcolumnas];
for (int i = 0; i < numcolumnas; i++) {
fila[i] = result.getObject(i + 1);
}
modelo.addRow(fila);
}
} catch (ClassNotFoundException e) {
} catch (SQLException sqe) {
}
// TODO add your handling code here:
}
private void jMenu2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
añadirTabla();
}
public void añadirTabla() {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conexion = DriverManager.getConnection("jdbc:mysql://192.168.100.128/mibase", "asis", "titanic24");
Statement comando = conexion.createStatement();
ResultSet result = comando.executeQuery("select * from dades_pers");
ResultSetMetaData rsMD = result.getMetaData();
int numcolumnas = rsMD.getColumnCount();
DefaultTableModel modelo = new DefaultTableModel();
this.jTable2.setModel(modelo);
for (int x = 1; x <= numcolumnas; x++) {
modelo.addColumn(rsMD.getColumnLabel(x));
}
while (result.next()) {
Object[] fila = new Object[numcolumnas];
for (int i = 0; i < numcolumnas; i++) {
fila[i] = result.getObject(i + 1);
}
modelo.addRow(fila);
}
} catch (ClassNotFoundException e) {
} catch (SQLException sqe) {
}
}
public String [] modify() {
String[] registros = new String[4];
int i = jTable2.getSelectedRow();
if (i == -1) {
JOptionPane.showMessageDialog(null, "Debes selecioonar una fila");
new Modificar(this, true).setVisible(false);
} else {
registros[0] = (String) jTable2.getValueAt(i, 0).toString();
registros[1] = (String) jTable2.getValueAt(i, 1).toString();
registros[2] = (String) jTable2.getValueAt(i, 2).toString();
registros[3] = (String) jTable2.getValueAt(i, 3).toString();
}
return registros;
}
/**
* #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(DniFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(DniFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(DniFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(DniFrame.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 DniFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
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.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable2;
// End of variables declaration
}
//the jdialog (the second frame);
public class Modificar extends javax.swing.JDialog {
private DniFrame p;
/**
* Creates new form Modificar
*/
public Modificar(java.awt.Frame parent, boolean modal) {
super(parent, modal);
this.p= (DniFrame)parent;
initComponents();
}
public void SetRecoger(String[] v) {
String nif = v[0];
String nom = v[1];
String cognom =v[2];
String tel = v[3];
String []datos ={nif,nom,cognom,tel};
jTextField5.setText(nif);
jTextField6.setText(nom);
jTextField7.setText(cognom);
jTextField8.setText(tel);
}
/**
* 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() {
jPanel2 = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
jTextField5 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
jTextField7 = new javax.swing.JTextField();
jTextField8 = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jLabel5.setText("Nom");
jTextField5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField5ActionPerformed(evt);
}
});
jTextField6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField6ActionPerformed(evt);
}
});
jTextField7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField7ActionPerformed(evt);
}
});
jTextField8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField8ActionPerformed(evt);
}
});
jLabel6.setText("NIF");
jLabel7.setText("Cognoms");
jLabel8.setText("Telefon");
jButton2.setText("Desar les dades");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Tancar");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Estat"));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
.addContainerGap())
);
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.TRAILING, false)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(31, 31, 31)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(78, 78, 78)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap(23, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(17, 17, 17)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(15, 15, 15)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 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)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel2, 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()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 10, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField8ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(afegir.class.getName()).log(Level.SEVERE, null, ex);
}
try {
Connection conexion = DriverManager.getConnection("jdbc:mysql://192.168.100.128/mibase", "asis", "titanic24");
Statement comando = conexion.createStatement();
String nif = jTextField5.getText();
String nom = jTextField6.getText();
String cognom = jTextField7.getText();
String tel = jTextField8.getText();
comando.executeUpdate("UPDATE dades_pers SET nom= '" + nom + "',cognoms='" + cognom + "',telefon= '" + tel + "' where nif= '" + nif + "'");
conexion.close();
jLabel1.setText("Datos Modificados correctamente");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error al modificar los datos" + e);
}
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
//
/**
* #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(Modificar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Modificar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Modificar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Modificar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Modificar dialog = new Modificar(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
#Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
Thanks!!
You are calling the method SetRecoger in your DniFrame without passing any arguments to the method.
The method as you have defined it in your Modificar dialog requires a String array as an argument.
public void SetRecoger(String[] v) {....}
Since your modify() method returns a String array, Try this:
String[] mod = modify();
Modificar m = new Modificar(this, true);
m.SetRecoger(mod);
new Modificar(this, true).setVisible(true);
Related
I have studied creating a chat program from a tutorial site and I applied all of the above in the explanation but I have a problem is the inability to transfer files and images between the server and the client.
This code is used in chat.
I've done a lot of experiments, but I can't solve the problem.
MessageList:
public class MessageList extends Thread{
ServerSocket srever;
int port=1000;
WritableGUI gui;
private ObjectOutputStream out;
public MessageList(WritableGUI gui,int port){
this.port=port;
this.gui=gui;
try {
srever=new ServerSocket(port);
} catch (IOException e) {
Logger.getLogger(MessageList.class.getName()).log(Level.SEVERE, null, e);
}
}
#Override
public void run(){
Socket clientSocket;
try {
while ((clientSocket=srever.accept())!=null) {
InputStream is = clientSocket.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = br.readLine();
if(line !=null){
gui.write(line);
}
}
} catch (Exception e) {
Logger.getLogger(MessageList.class.getName()).log(Level.SEVERE, null, e);
}
}
}
Message:
public class MessageTransmitter extends Thread{
String message , hostname;
int port=1000;
int filesize=2022386;
int bytesRead;
int currentTot = 0;
public MessageTransmitter(){
}
public MessageTransmitter(String message ,String hostname,int port ){
this.message=message;
this.hostname=hostname;
this.port=port;
}
#Override
public void run(){
try {
Socket s =new Socket(hostname,port);
s.getOutputStream().write(message.getBytes());
s.close();
} catch (IOException e) {
Logger.getLogger(MessageTransmitter.class.getName()).log(Level.SEVERE, null, e);
}
}
}
WritableGUI :
public interface WritableGUI {
void write(String s);
}
Please help me solve this problem.
public class MainScreen extends javax.swing.JFrame implements WritableGUI {
public MainScreen() {
initComponents();
}
#SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
ip = new javax.swing.JTextField();
Sender = new javax.swing.JTextField();
listen = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
chat = new javax.swing.JTextArea();
mass = new javax.swing.JTextField();
sendB = new javax.swing.JButton();
receiver = new javax.swing.JTextField();
Exit = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(208, 204, 202));
ip.setFont(new java.awt.Font("Copperplate Gothic Bold", 0, 13)); // NOI18N
ip.setText("localhost");
ip.setToolTipText("");
ip.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ipActionPerformed(evt);
}
});
Sender.setText("200");
listen.setBackground(new java.awt.Color(255, 192, 27));
listen.setFont(new java.awt.Font("Copperplate Gothic Bold", 0, 13)); // NOI18N
listen.setText("Listen");
listen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
listenActionPerformed(evt);
}
});
chat.setColumns(20);
chat.setRows(5);
jScrollPane1.setViewportView(chat);
sendB.setBackground(new java.awt.Color(255, 192, 27));
sendB.setFont(new java.awt.Font("Copperplate Gothic Bold", 0, 13)); // NOI18N
sendB.setText("send");
sendB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sendBActionPerformed(evt);
}
});
receiver.setText("100");
Exit.setBackground(new java.awt.Color(255, 192, 27));
Exit.setFont(new java.awt.Font("Copperplate Gothic Bold", 0, 13)); // NOI18N
Exit.setText("Exit");
Exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ExitActionPerformed(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()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)
.addComponent(mass, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Sender)
.addComponent(receiver)
.addComponent(ip, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
.addComponent(listen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(Exit, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(sendB, 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()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(219, 219, 219)
.addComponent(sendB, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(Sender, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(receiver, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ip, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(listen, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(5, 5, 5)
.addComponent(Exit, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mass, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(25, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
MessageList listener;
private void listenActionPerformed(java.awt.event.ActionEvent evt) {
listener =new MessageList(this, Integer.parseInt(Sender.getText()));
listener.start();
}
private void sendBActionPerformed(java.awt.event.ActionEvent evt) {
MessageTransmitter mt = new MessageTransmitter(mass.getText(), ip.getText(), Integer.parseInt(receiver.getText()));
mt.start();
}
private void ipActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
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(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainScreen.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 MainScreen().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton Exit;
private javax.swing.JTextField Sender;
private javax.swing.JTextArea chat;
private javax.swing.JTextField ip;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton listen;
private javax.swing.JTextField mass;
private javax.swing.JTextField receiver;
private javax.swing.JButton sendB;
// End of variables declaration
#Override
public void write(String ss) {
chat.append(ss+System.lineSeparator());
}
}
I have a jtable set up that I've populated with values from a .csv file. I need to retrieve all of the values from the jtable and graph them, but am having trouble figuring it out. I'm using JFreeChart and have set up the graph but am absolutely stuck on how to populate the line graph with values from the JTable.
Code that I've tried, but isn't working and simply halts the application when I hit the graph button:
//instantiate the data series and the chart
int row = tableRadio.getRowCount();
int column = tableRadio.getColumnCount();
for (int r = 0; r < row; r++) {
for (int c = 0; c < column; c++) {
series.add(r, c);
}
}
Entire Code:
//data used by all methods
DefaultTableModel tableModel;
//Global variables
XYSeries series; //series of data that will be added to the graph
XYSeriesCollection dataSet; //a collection object holds the series
JFreeChart chart; //chart to be placed on the panel
public MainWindow() {
initComponents();
//instantiate the DefaultTableModel
tableModel = (DefaultTableModel) tableRadio.getModel();
//instantiate the data series and the chart
series = new XYSeries("Random Numbers");
dataSet = new XYSeriesCollection(series);
chart = ChartFactory.createXYLineChart("Radio Astronomy Graphing", "Time", "Sensor Value", dataSet);
//display the graphing chart on the panel
panelGraph.add(new ChartPanel(chart), BorderLayout.CENTER);
panelGraph.revalidate();
//center the applications window upon start
this.setLocationRelativeTo(null);
}
/**
* 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() {
buttonLoad = new javax.swing.JButton();
buttonGraph = new javax.swing.JButton();
buttonSave = new javax.swing.JButton();
buttonAdd = new javax.swing.JButton();
buttonEdit = new javax.swing.JButton();
buttonRemove = new javax.swing.JButton();
labelValue = new javax.swing.JLabel();
tfMonth = new javax.swing.JTextField();
tfValue = new javax.swing.JTextField();
tfDay = new javax.swing.JTextField();
labelHour = new javax.swing.JLabel();
labelMin = new javax.swing.JLabel();
labelYear = new javax.swing.JLabel();
labelDay = new javax.swing.JLabel();
labelMonth = new javax.swing.JLabel();
tfYear = new javax.swing.JTextField();
tfHour = new javax.swing.JTextField();
tfMin = new javax.swing.JTextField();
panelGraph = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
tableRadio = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
buttonLoad.setText("Load File");
buttonLoad.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonLoadActionPerformed(evt);
}
});
buttonGraph.setText("Graph Data");
buttonGraph.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonGraphActionPerformed(evt);
}
});
buttonSave.setText("Save");
buttonSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonSaveActionPerformed(evt);
}
});
buttonAdd.setText("Add");
buttonAdd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonAddActionPerformed(evt);
}
});
buttonEdit.setText("Edit");
buttonEdit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonEditActionPerformed(evt);
}
});
buttonRemove.setText("Remove");
buttonRemove.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonRemoveActionPerformed(evt);
}
});
labelValue.setText("Sensor Value:");
tfValue.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfValueActionPerformed(evt);
}
});
labelHour.setText("Hour");
labelMin.setText("Minute");
labelYear.setText("Year");
labelDay.setText("Day");
labelMonth.setText("Month");
panelGraph.setLayout(new java.awt.BorderLayout());
tableRadio.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Date and Time", "Sensor Value"
}
) {
boolean[] canEdit = new boolean [] {
false, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane1.setViewportView(tableRadio);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(41, 41, 41)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(buttonLoad, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonSave, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonGraph, javax.swing.GroupLayout.Alignment.TRAILING))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(buttonAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(84, 84, 84)
.addComponent(labelMonth)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(labelDay)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(tfDay, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(buttonEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(buttonRemove, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(87, 87, 87)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(labelValue)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfValue, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(labelHour)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfHour, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(15, 15, 15)
.addComponent(labelMin)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(tfMin, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(labelYear)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfYear, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 372, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(panelGraph, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 17, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(panelGraph, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonLoad)
.addComponent(buttonAdd)
.addComponent(labelMonth)
.addComponent(tfMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(labelDay)
.addComponent(tfDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(labelYear)
.addComponent(tfYear, 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(buttonGraph)
.addComponent(buttonEdit)
.addComponent(tfHour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(labelHour)
.addComponent(labelMin)
.addComponent(tfMin, 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(buttonSave)
.addComponent(buttonRemove)
.addComponent(labelValue)
.addComponent(tfValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(35, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void buttonLoadActionPerformed(java.awt.event.ActionEvent evt) {
//Load file into table
//create JFileChooser
JFileChooser fileChooser = new JFileChooser();
fileChooser.showOpenDialog(null);
//create myFile and define the path
File myFile = fileChooser.getSelectedFile();
try{
//instantiate Scanner
Scanner inputStream = new Scanner(myFile);
for(int i=0; i < 12; i++){
inputStream.nextLine();
}
//split values into 2 arrays and insert into table
while (inputStream.hasNext()) {
String data = inputStream.next();
String[] values = data.split(",");
tableModel.insertRow(tableModel.getRowCount(), values);
}//end of while block
}//end of try block
catch(FileNotFoundException e) {
JOptionPane.showMessageDialog(this, "File Not Found");
}//end of catch block
}
private void buttonAddActionPerformed(java.awt.event.ActionEvent evt) {
//add info from text fields and combo boxes to table
try {
//create variables to hold the contents of what user has typed in
int Month = Integer.parseInt(tfMonth.getText());
int Day = Integer.parseInt(tfDay.getText());
int Year = Integer.parseInt(tfYear.getText());
int Hour = Integer.parseInt(tfHour.getText());
int Min = Integer.parseInt(tfMin.getText());
double Value = Double.parseDouble(tfValue.getText());
//add the info to the table
tableModel.insertRow(tableModel.getRowCount(), new Object[]{Month + "/" + Day + "/" + Year + " " + Hour + ":" + Min, Value });
//clear the controls on the interface
tfMonth.setText("");
tfDay.setText("");
tfYear.setText("");
tfHour.setText("");
tfMin.setText("");
tfValue.setText("");
}//end of try block
catch(NumberFormatException e) {
JOptionPane.showMessageDialog(this, "Please fill out all fields and enter only numbers");
}//end of catch block
}
private void buttonEditActionPerformed(java.awt.event.ActionEvent evt) {
//edit info based on row selected
//make sure a row is selected
if(tableRadio.getSelectedRow() >= 0){
//set the values in the table for all text fields
tableModel.setValueAt(tfMonth.getText() + "/" + tfDay.getText() + "/" + tfYear.getText() + " " + tfHour.getText() + ":" + tfMin.getText(), tableRadio.getSelectedRow(), 0);
tableModel.setValueAt(tfValue.getText(), tableRadio.getSelectedRow(), 1);
//clear the user interface controls after adding them to the table
tfMonth.setText("");
tfDay.setText("");
tfYear.setText("");
tfHour.setText("");
tfMin.setText("");
tfValue.setText("");
}//end of if block checking for selected row
else{
JOptionPane.showMessageDialog(this, "Please select a row.");
}//end of else block
}
private void buttonRemoveActionPerformed(java.awt.event.ActionEvent evt) {
//Delete the selected row
//Make sure a row is selected
if(tableRadio.getSelectedRow() >= 0){
//remove the row
tableModel.removeRow(tableRadio.getSelectedRow());
//clear the user interface controls after deleting a row
tfMonth.setText("");
tfDay.setText("");
tfYear.setText("");
tfHour.setText("");
tfMin.setText("");
tfValue.setText("");
}//end of if block
else{
JOptionPane.showMessageDialog(this, "Please select a row.");
}//end of else block
}
private void buttonGraphActionPerformed(java.awt.event.ActionEvent evt) {
//instantiate the data series and the chart
int row = tableRadio.getRowCount();
int column = tableRadio.getColumnCount();
for (int r = 0; r < row; r++) {
for (int c = 0; c < column; c++) {
series.add(r, c);
}
}
}
private void tfValueActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {
try {
// capture the whole screen
BufferedImage radioGraph = new Robot().createScreenCapture(
new Rectangle( panelGraph.getX(), panelGraph.getY(), panelGraph.getWidth(), panelGraph.getHeight() ) );
//Save as PNG
File file = new File("radioGraph.png");
ImageIO.write(radioGraph, "png", file);
JOptionPane.showMessageDialog(this, "radioGraph.png added to project folder");
}
catch(AWTException e) {
JOptionPane.showMessageDialog(this, "Error");
}
catch(IOException e){
JOptionPane.showMessageDialog(this, "Error");
}
}
/**
* #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(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainWindow.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 MainWindow().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton buttonAdd;
private javax.swing.JButton buttonEdit;
private javax.swing.JButton buttonGraph;
private javax.swing.JButton buttonLoad;
private javax.swing.JButton buttonRemove;
private javax.swing.JButton buttonSave;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel labelDay;
private javax.swing.JLabel labelHour;
private javax.swing.JLabel labelMin;
private javax.swing.JLabel labelMonth;
private javax.swing.JLabel labelValue;
private javax.swing.JLabel labelYear;
private javax.swing.JPanel panelGraph;
private javax.swing.JTable tableRadio;
private javax.swing.JTextField tfDay;
private javax.swing.JTextField tfHour;
private javax.swing.JTextField tfMin;
private javax.swing.JTextField tfMonth;
private javax.swing.JTextField tfValue;
private javax.swing.JTextField tfYear;
// End of variables declaration
Any Ideas on what might work for me? I've never had to get data from a table and graph it so this is all new to me. Please let me know if I've messed up somewhere.
series.add(r, c);
That won't do anything. You are just getting the indexes of your loop.
You want something like:
series.add( tableRadio.getValueAt(r, c) );
Of course the getValueAt(...) method just returns an Object so you will need to convert the Object to the data type needed for the series Object.
Also if you need two parameter for the series Object, then you will obviously need two getValueAt(...) statements. Maybe you only have two columns, so you only need a single loop on the rows and then you get the value from column 0 and column 1? Only you know the data you have in your table.
I'm trying to build an application that has a console like text-area, I can't get text to be either appended or added to the text inside the jtextarea. I was wondering if anyone could help me work out why as my code is showing no errors?
code as follows:
Form 1:
package com.company;
public class Form1 extends javax.swing.JFrame {
private javax.swing.JButton btnComboBox;
private javax.swing.JComboBox<String> comboOne;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
public Form1() {
initComponents();
}
#SuppressWarnings("unchecked")
private void initComponents() {
jLabel2 = new javax.swing.JLabel();
comboOne = new javax.swing.JComboBox<>();
jLabel3 = new javax.swing.JLabel();
btnComboBox = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel2.setText("SELECT PRINTER:");
comboOne.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Printer 1", "Printer 2", "Printer 3", "Printer 4" }));
comboOne.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboOneActionPerformed(evt);
}
});
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel3.setText("ZEBRA PRINTER ");
btnComboBox.setText("GO");
btnComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnComboBoxActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(154, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(comboOne, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
.addComponent(btnComboBox, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGap(153, 153, 153))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comboOne, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btnComboBox)
.addContainerGap(176, Short.MAX_VALUE))
);
pack();
}
private void comboOneActionPerformed(java.awt.event.ActionEvent evt) {
Object selected = comboOne.getSelectedItem().toString();
}
private void btnComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
// Opens a new form, converts the object selected in combobox too a string
// Passes string to openMe on form 2
Form2 f2 = new Form2();
f2.openMe(comboOne.getSelectedItem().toString());
this.setEnabled(false);
}
public static void main(String args[]) {
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(Form1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Form1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Form1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Form1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Form1().setVisible(true);
}
});
}
}
Form 2:
package com.company;
public class Form2 extends javax.swing.JFrame {
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel3;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jta;
public Form2() {
initComponents();
jta.append("----- Console Output ------\n");
jta.append("----------------------------------");
}
#SuppressWarnings("unchecked")
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jta = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Console");
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel3.setText("ZEBRA PRINTER ");
jta.setColumns(20);
jta.setRows(5);
jScrollPane2.setViewportView(jta);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(158, 158, 158)
.addComponent(jLabel3)))
.addGap(0, 192, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jLabel3)
.addGap(17, 17, 17)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}
public void openMe(String message) {
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(Form2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Form2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Form2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Form2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Form2().setVisible(true);
new Form1().setVisible(false);
}
});
System.out.println("----- Console Output ------");
System.out.println("---------------------------");
System.out.println("Printer selected: "+ message);
System.out.println("---------------------------");
System.out.println("\n");
jta.setText(message);
jta.append("Printer selected:"+message);
}
}
Any help appreciated as always.
Here is my complete code...
When I run this and click button its showing nullpointer exception at resultset
package com.openbravo.pos.followup;
/**
*
* #author manideep
*/
public class FollowUp extends javax.swing.JPanel implements JPanelView, BeanFactoryApp {
private AppView m_App;
protected DataLogicCustomers dlCustomers;
// CustomerInfo customer;
private AppConfig conf;
// private ListProvider lpr
private DefaultTableModel modelx, model;
protected DataLogicFollowUp dlFollowUp;
/**
* Creates new form FollowUp
*/
public FollowUp() {
initComponents();
String[] args = {};
conf = new AppConfig(args);
conf.load();
jLabel3.setText("");
}
/**
* 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">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
m_jTicketId3 = new javax.swing.JLabel();
m_jTicketId1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jcmdOK = new javax.swing.JButton();
jcmdCancel = new javax.swing.JButton();
jCheckBox1 = new javax.swing.JCheckBox();
jLabel1.setText("Enter Date");
jTextField1.setPreferredSize(new java.awt.Dimension(90, 19));
jButton1.setText("Submit");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel3.setText("jLabel3");
jButton3.setText("Customer");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setText("Product");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
m_jTicketId3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
m_jTicketId3.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")), javax.swing.BorderFactory.createEmptyBorder(1, 4, 1, 4)));
m_jTicketId3.setOpaque(true);
m_jTicketId3.setPreferredSize(new java.awt.Dimension(160, 25));
m_jTicketId3.setRequestFocusEnabled(false);
m_jTicketId1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
m_jTicketId1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")), javax.swing.BorderFactory.createEmptyBorder(1, 4, 1, 4)));
m_jTicketId1.setOpaque(true);
m_jTicketId1.setPreferredSize(new java.awt.Dimension(160, 25));
m_jTicketId1.setRequestFocusEnabled(false);
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()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))
.addGap(154, 154, 154)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(m_jTicketId1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(m_jTicketId3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jLabel3))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton3)
.addComponent(m_jTicketId3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton4))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(17, 17, 17)
.addComponent(m_jTicketId1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 0, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel3)
.addGap(24, 24, 24))
);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Customer", "Phone No.", "Product", "Last sold Qty.", "Consumption", "last sale date", "Delivery Date", "Remark 1", "Remark 2", "Stock(Y/N)", "Invoice No."
}
) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
};
boolean[] canEdit = new boolean [] {
false, false, false, false, false, false, false, true, true, true, true
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jTable1.getTableHeader().setReorderingAllowed(false);
jScrollPane1.setViewportView(jTable1);
jTable1.getColumnModel().getColumn(0).setResizable(false);
jTable1.getColumnModel().getColumn(1).setResizable(false);
jTable1.getColumnModel().getColumn(3).setResizable(false);
jTable1.getColumnModel().getColumn(4).setResizable(false);
jTable1.getColumnModel().getColumn(5).setResizable(false);
jTable1.getColumnModel().getColumn(6).setResizable(false);
jTable1.getColumnModel().getColumn(7).setResizable(false);
jTable1.getColumnModel().getColumn(7).setPreferredWidth(0);
jTable1.getColumnModel().getColumn(8).setResizable(false);
jTable1.getColumnModel().getColumn(9).setResizable(false);
jTable1.getColumnModel().getColumn(10).setResizable(false);
jcmdOK.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_ok.png"))); // NOI18N
jcmdOK.setText("OK");
jcmdOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jcmdOKActionPerformed(evt);
}
});
jcmdCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_cancel.png"))); // NOI18N
jcmdCancel.setText("Cancel");
jcmdCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jcmdCancelActionPerformed(evt);
}
});
jCheckBox1.setText("Select All");
jCheckBox1.setMaximumSize(new java.awt.Dimension(0, 0));
jCheckBox1.setPreferredSize(new java.awt.Dimension(0, 0));
jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(353, 353, 353)
.addComponent(jcmdOK)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jcmdCancel)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1408, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jCheckBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(74, 74, 74))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, 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(8, 8, 8)
.addComponent(jCheckBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 406, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jcmdOK)
.addComponent(jcmdCancel))
.addGap(31, 31, 31))
);
}// </editor-fold>//GEN-END:initComponents
private void getListSRLine(Element e){
String customer= getAttrDataFromElement((Element)e.getElementsByTagName("customer").item(0),"identifier");
String phone= getCharacterDataFromElement((Element)e.getElementsByTagName("phone").item(0));
String product=getAttrDataFromElement((Element)e.getElementsByTagName("product").item(0),"identifier");
String lastsoldqty=getCharacterDataFromElement((Element)e.getElementsByTagName("lastsoldqty").item(0));
String consumption=getCharacterDataFromElement((Element)e.getElementsByTagName("consumption").item(0));
String lastsaledate=getCharacterDataFromElement((Element)e.getElementsByTagName("lastsaledate").item(0));
String deliverydate=getCharacterDataFromElement((Element)e.getElementsByTagName("deliverydate").item(0));
String remark1=getCharacterDataFromElement((Element)e.getElementsByTagName("remark1").item(0));
String remark2=getCharacterDataFromElement((Element)e.getElementsByTagName("remark2").item(0));
String stock=getCharacterDataFromElement((Element)e.getElementsByTagName("stock").item(0));
String invoiceno=getCharacterDataFromElement((Element)e.getElementsByTagName("invoiceno").item(0));
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
model.addRow(new Object[]{customer,phone,product,lastsoldqty,consumption,lastsaledate,deliverydate,remark1,remark2,stock,invoiceno});
//sortColumn(model, 1, true);
model.fireTableDataChanged();
jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
jTable1.setAutoCreateRowSorter(true);
jTable1.getColumnModel().getColumn(0).setPreferredWidth(150);
jTable1.getColumnModel().getColumn(1).setPreferredWidth(120);
jTable1.getColumnModel().getColumn(2).setPreferredWidth(200);
jTable1.getColumnModel().getColumn(3).setPreferredWidth(50);
jTable1.getColumnModel().getColumn(4).setPreferredWidth(100);
jTable1.getColumnModel().getColumn(5).setPreferredWidth(100);
jTable1.getColumnModel().getColumn(6).setPreferredWidth(100);
jTable1.getColumnModel().getColumn(7).setPreferredWidth(100);
jTable1.getColumnModel().getColumn(8).setPreferredWidth(100);
jTable1.getColumnModel().getColumn(9).setPreferredWidth(100);
jTable1.getColumnModel().getColumn(10).setPreferredWidth(100);
jTable1.getColumnModel().getColumn(11).setPreferredWidth(0);
}
private void executeSearch() {
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your PostgreSQL JDBC Driver? "
+ "Include in your library path!");
e.printStackTrace();
return;
}
System.out.println("PostgreSQL JDBC Driver Registered!");
Connection connection = null;
try {
connection = DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/openbravopos", "postgres",
"postgres");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
if (connection != null) {
try {
System.out.println("You made it, take control your database now!");
int colCount;
String [] headers;
Statement stmt = null;
// rs=(ResultSet) dlFollowUp.getFollowUpList();
// getFollowUplist();
ResultSet rs = null;
rs = stmt.executeQuery("SELECT id,customer,phone,product,lastsoldqty,consumption,lastsaledate,deliverydate,remark1,remark2,stock,invoiceno FROM followup");
java.sql.ResultSetMetaData rsmd = rs.getMetaData();
int colNo = rsmd.getColumnCount();
while(rs.next()){
Object[] objects = new Object[colNo];
for(int i=0;i<colNo;i++){
objects[i]=rs.getObject(i+1);
}
model.addRow(objects);
}
jTable1.setModel(model);
} catch (SQLException ex) {
Logger.getLogger(FollowUp.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
System.out.println("Failed to make connection!");
}
}
public static String getAttrDataFromElement(Element e,String attr){
return e.getAttribute(attr);
}
public static String getCharacterDataFromElement(Element e) {
Node child = e.getFirstChild();
if (child instanceof CharacterData) {
CharacterData cd = (CharacterData) child;
return cd.getData();
}
return "";
}
private void jcmdOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmdOKActionPerformed
// jButton1ActionPerformed(evt);
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
//dispose();
}//GEN-LAST:event_jcmdOKActionPerformed
private void jcmdCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmdCancelActionPerformed
dispose();
}//GEN-LAST:event_jcmdCancelActionPerformed
private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jCheckBox1ActionPerformed
String field="";
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
jLabel3.setText("");
executeSearch();
// entity = response.getafilter();
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
JCustomerFinder finder = JCustomerFinder.getCustomerFinder(this, dlCustomers);
finder.setVisible(true);
CustomerInfo custsel=finder.getSelectedCustomer();
m_jTicketId3.setText(custsel.printName());
}//GEN-LAST:event_jButton3ActionPerformed
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
/* // TODO add your handling code here:
JProductFinder finder = JProductFinder.getProductFinder(this, dlSales, m_App.getInventoryLocation(),m_App);
finder.setVisible(true);
ProductAttrInfoExt prod = finder.getSelectedProduct();
m_jTicketId1.setText(prod.getName());*/
}//GEN-LAST:event_jButton4ActionPerformed
private void dispose(){
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
model.setRowCount(0);
jLabel3.setText(null);
model.fireTableDataChanged();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
private javax.swing.JButton jcmdCancel;
private javax.swing.JButton jcmdOK;
private javax.swing.JLabel m_jTicketId1;
private javax.swing.JLabel m_jTicketId3;
// End of variables declaration//GEN-END:variables
#Override
public String getTitle() {
return "Follow Up";
}
#Override
public void activate() throws BasicException {
resetFollowUp();
}
public void resetFollowUp(){
jTextField1.setText("");
m_jTicketId3.setText("");
m_jTicketId1.setText("");
}
#Override
public boolean deactivate() {
return true;
}
#Override
public JComponent getComponent() {
return this;
}
#Override
public void init(AppView app) throws BeanFactoryException {
jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
jTable1.getColumnModel().getColumn(0).setPreferredWidth(150);
jTable1.getColumnModel().getColumn(1).setPreferredWidth(150);
jTable1.getColumnModel().getColumn(2).setPreferredWidth(250);
jTable1.getColumnModel().getColumn(3).setPreferredWidth(100);
jTable1.getColumnModel().getColumn(4).setPreferredWidth(200);
jTable1.getColumnModel().getColumn(5).setPreferredWidth(250);
jTable1.getColumnModel().getColumn(6).setPreferredWidth(250);
jTable1.getColumnModel().getColumn(7).setPreferredWidth(250);
jTable1.getColumnModel().getColumn(8).setPreferredWidth(200);
jTable1.getColumnModel().getColumn(9).setPreferredWidth(200);
jTable1.getColumnModel().getColumn(10).setPreferredWidth(100);
DefaultTableModel modelx = (DefaultTableModel) jTable1.getModel();
for(int j=0;j< modelx.getRowCount();j++){
}
m_App=app;
// setWarehouse(m_App.getWarehouseSearchKey());
dlCustomers = (DataLogicCustomers) m_App.getBean("com.openbravo.pos.customers.DataLogicCustomers");
}
#Override
public Object getBean() {
return this;
}
}
You never initialise the Statement object....
Statement stmt = null; // Look ma, I'm null
// rs=(ResultSet) dlFollowUp.getFollowUpList();
// getFollowUplist();
ResultSet rs = null;
// Look ma, I'm still null
rs = stmt.executeQuery("SELECT id,customer,phone,product,lastsoldqty,consumption,lastsaledate,deliverydate,remark1,remark2,stock,invoiceno FROM followup");
You need to create the stmt before you can use...
stmt = connection.createStatement();
You may find reading through the JDBC tutorials of benifit
Problem #2
You define model as instance variable at the start of your FollowUp class...
private DefaultTableModel modelx, model;
But you never initialise it to anything....
I would imagine, based on your code, you would need to initialise it in your executeSearch method...
// You will need to fill this out with appropriate values,
// the number of columns in you JTable should match the
// the number columns from your query...
Object[] columns = new Object[]{....};
model = new DefaultTableModel(columns, 0);
while(rs.next()){
Object[] objects = new Object[colNo];
for(int i=0;i<colNo;i++){
objects[i]=rs.getObject(i+1);
}
model.addRow(objects);
}
I have created a login where a user can put in their username , password and select their role. When I press Login button nothing happens. Could you please look at my code and tell me what I did wrong :)
class Login.java:
import java.sql.*;
public class Login extends javax.swing.JFrame {
Connection con =null;
PreparedStatement stmt = null;
ResultSet rs = null;
Control c = new Control();
/**
* Creates new form Login
*/
public Login() {
try {
initComponents();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xxx?user=yyyy&password=zzzzz");
} catch (SQLException e) {
e.toString();
}
}
/**
* 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() {
jLabel5 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jComboBox1 = new javax.swing.JComboBox();
user_f = new javax.swing.JTextField();
pass_f = new javax.swing.JPasswordField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel6 = new javax.swing.JLabel();
jLabel5.setText("jLabel5");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("MyWindow");
jComboBox1.setMaximumRowCount(2);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Manager", "Staff" }));
jComboBox1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
jLabel1.setText("Username");
jLabel2.setText("Password");
jLabel3.setText("Role");
jButton1.setText("Login");
jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Exit");
jButton2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fish/oie_transparent (2).png"))); // NOI18N
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(62, 62, 62)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(37, 37, 37)
.addComponent(jButton2))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel1))
.addGap(34, 34, 34)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(pass_f)
.addComponent(user_f)
.addComponent(jComboBox1, 0, 120, Short.MAX_VALUE))))
.addContainerGap(121, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel6)
.addGap(51, 51, 51))
);
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3});
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2});
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(user_f, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(pass_f, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)))
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton2)
.addGap(29, 29, 29))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton1)
.addContainerGap())))
);
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)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try{
String user = user_f.getText();
String pass = pass_f.getText();
String role = jComboBox1.getSelectedItem().toString();
String sql = "Select Log, Pass, Role from Logpass where Log = '"+user+"' Pass = '"+pass+"' Role = '"+role+"' ";
stmt=con.prepareStatement(sql);
rs= stmt.executeQuery();
if(rs.next()){
this.setVisible(false);
c.setVisible(true);
}
else{
JOptionPane.showMessageDialog(null, "Wrong username or password!");
}
}
catch(SQLException e){
System.out.println(e);
}
}
/**
* #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(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Login.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 Login().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JPanel jPanel1;
private javax.swing.JPasswordField pass_f;
private javax.swing.JTextField user_f;
// End of variables declaration
}
Thank you:)
Select Log, Pass and Role from Logpass where Log = '"+user+"' Pass = '"+pass+"' Role = '"+role+"'
does not seem like a correct SQL query to me. Try
Select Log, Pass, Role from Logpass where Log = '"+user+"' and Pass = '"+pass+"' and Role = '"+role+"'
Also, e.toString(); does not print the exception that might be thrown when executing the query.