In swing based project i create a master detail class using wizard and populate J Table and create a button Record in another class and put object of master detail class in action listener of Record button.But when i click Record button master detail class run butt not show GUI window while when i run it as main class or run direct it run successfully and show GUI window and also show record from database.I am confused because other classes run on click Record button if i replace object of master client class with any other class but only master detail class not show GUI window.Here is code of two class one is master detail with name of BrRecord and other class which handle it with name of Balance.Thanks.
package my.soft;
import java.awt.EventQueue;
import java.beans.Beans;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.RollbackException;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class BrRecord extends javax.swing.JPanel {
public BrRecord() {
initComponents();
if (!Beans.isDesignTime()) {
entityManager.getTransaction().begin();
}
}
private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {
entityManager.getTransaction().rollback();
entityManager.getTransaction().begin();
java.util.Collection data = query.getResultList();
for (Object entity : data) {
entityManager.refresh(entity);
}
list.clear();
list.addAll(data);
}
private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {
int[] selected = masterTable.getSelectedRows();
List<my.soft.Expance1> toRemove = new ArrayList<my.soft.Expance1>(selected.length);
for (int idx = 0; idx < selected.length; idx++) {
my.soft.Expance1 e = list.get(masterTable.convertRowIndexToModel(selected[idx]));
toRemove.add(e);
entityManager.remove(e);
}
list.removeAll(toRemove);
}
private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {
my.soft.Expance1 e = new my.soft.Expance1();
entityManager.persist(e);
list.add(e);
int row = list.size() - 1;
masterTable.setRowSelectionInterval(row, row);
masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true));
}
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
} catch (RollbackException rex) {
rex.printStackTrace();
entityManager.getTransaction().begin();
List<my.soft.Expance1> merged = new ArrayList<my.soft.Expance1>(list.size());
for (my.soft.Expance1 e : list) {
merged.add(entityManager.merge(e));
}
list.clear();
list.addAll(merged);
}
}
private javax.swing.JTextField breakfastField;
private javax.swing.JLabel breakfastLabel;
private javax.swing.JTextField dateField;
private javax.swing.JLabel dateLabel;
private javax.swing.JButton deleteButton;
private javax.persistence.EntityManager entityManager;
private javax.swing.JTextField expance1Field;
private javax.swing.JLabel expance1Label;
private java.util.List<my.soft.Expance1> list;
private javax.swing.JScrollPane masterScrollPane;
private javax.swing.JTable masterTable;
private javax.swing.JButton newButton;
private javax.persistence.Query query;
private javax.swing.JButton refreshButton;
private javax.swing.JButton saveButton;
private org.jdesktop.beansbinding.BindingGroup bindingGroup;
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() {
public void run() {
new BrRecord().setVisible(true);
JFrame frame = new JFrame();
frame.setContentPane(new BrRecord());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
});
}
}
Balance
source
package my.soft;
//import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
import static com.sun.corba.se.spi.presentation.rmi.StubAdapter.request;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import static java.lang.System.out;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import static java.text.DateFormat.Field.DAY_OF_MONTH;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import static java.util.Calendar.MONTH;
import static java.util.Calendar.YEAR;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class Balance extends javax.swing.JFrame { public Balance() {
initComponents();
CurrentDate();
conn = MySql.connectToDB();
}
private void bRecordActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
BrRecord Br = new BrRecord();
Br.setVisible(true);
// DISPOSE_ON_CLOSE();
Close();
}
public static void main(String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Balance().setVisible(true);
}
});
}