Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training Big Data and Hadoop Training Java Training  
 

How to call the run method from another class?

Ads

 
 

Share on Google+Share on Google+

idomiralin
How to call the run method from another class?
0 Answer(s)      4 years and 11 months ago
Posted in : Java Beginners

Sorry, if this is a stupid question.

I would like to find out how to call the run method that is located in

java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new FereastraPrincipala().setVisible(true); from the class AdaugaComanda.java.

The run method is declared in FereastraPrincipala.java and I want to call this from AdaugaComanda.java, so that changes can be seen to FereastraPrincipala after introducing values in the textfields from AdaugaChitanta.java. If I don't call a method, then I have to run FereastraPrincipala.java again, in order to see the new info in the JTabbedPane.

Here is the code for FereastraPrincipala.java

package sakila.ui;

 import java.util.List;
 import java.util.Vector;
 import javax.swing.table.DefaultTableModel;
 import org.hibernate.Session;
 import sakila.entity.*;
 import sakila.util.HibernateUtil;

public class FereastraPrincipala extends javax.swing.JFrame {

public FereastraPrincipala() {
    initComponents();
}

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
    AdaugaComanda ac = new AdaugaComanda();
    ac.setVisible(true);
}                                          

public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new Runnable() {

        public void run() {
            new FereastraPrincipala().setVisible(true);
            Session session = HibernateUtil.getSessionFactory().openSession();

    try{

    List<Comanda> comenzi = session.createQuery("from Comanda").list();

    Vector<String> tableHeaders = new Vector<String>();
    Vector tableData = new Vector();
    tableHeaders.add("IdComanda");
    tableHeaders.add("Depozit");
    tableHeaders.add("Furnizor");
    tableHeaders.add("Client");
    tableHeaders.add("Produs");
    tableHeaders.add("Cantitate");
    tableHeaders.add("Unit de mas");

    for (Comanda comanda : comenzi) {
        Vector <Object> oneRow = new Vector <Object>();
        oneRow.add(comanda.getIdcomanda());
        oneRow.add(comanda.getDepozit() == null ? "" : comanda.getDepozit().toString());
        oneRow.add(comanda.getFurnizor() == null ? "" : comanda.getFurnizor().toString());
        oneRow.add(comanda.getClient() == null ? "" : comanda.getClient().toString());
        oneRow.add(comanda.getProdus() == null ? "" : comanda.getProdus().toString());
        oneRow.add(comanda.getCantitate());
        oneRow.add(comanda.getUnitmas());

        tableData.add(oneRow);

        }
   ComandaTable.setModel(new DefaultTableModel(tableData, tableHeaders));    

       }catch (Exception he){
        he.printStackTrace();
    }
 }                              
    });
}
}

Here is the code for AdaugaComanda.java

package sakila.ui;

  import java.io.EOFException;
  import java.util.List;
  import sakila.entity.*;
  import sakila.service.Functie;
  import sakila.entity.Client;

 public class AdaugaComanda extends javax.swing.JDialog {

public AdaugaComanda() {
    initComponents();
    initComboBoxes();
}

   private void initComboBoxes() {

    DepozitComboBox.removeAllItems();
    FurnizorComboBox.removeAllItems();
    ClientComboBox.removeAllItems();
    ProdusComboBox.removeAllItems();

    System.out.println("sterge itemurile");

    List<Depozit> depozite = (List<Depozit>) sakila.client.Client.citeste(Functie.LISTEAZA_DEPOZITE);
    for (Depozit depozit : depozite)
        DepozitComboBox.addItem(depozit);

    List<Furnizor> furnizori = (List<Furnizor>) sakila.client.Client.citeste(Functie.LISTEAZA_FURNIZORI);
    for (Furnizor furnizor : furnizori)
        FurnizorComboBox.addItem(furnizor);

    List<Client> clienti = (List<Client>) sakila.client.Client.citeste(Functie.LISTEAZA_CLIENTI);
    for (Client client : clienti)
        ClientComboBox.addItem(client);

    List<Produs> produse = (List<Produs>) sakila.client.Client.citeste(Functie.LISTEAZA_PRODUSE);
    for (Produs produs : produse)
        ProdusComboBox.addItem(produs);
    System.out.println("adaugaitemuri"); 

}

private void ClientComboBoxActionPerformed(java.awt.event.ActionEvent evt) {                                               
    // TODO add your handling code here:
}                                              

private void InsereazaButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                
    runQueryBasedOnInsert();
}                                               

 private void runQueryBasedOnInsert(){

    Comanda comanda = new Comanda();

    Depozit depozit = (Depozit)DepozitComboBox.getSelectedItem();
    comanda.setDepozit(depozit);

    Furnizor furnizor = ((Furnizor)FurnizorComboBox.getSelectedItem());
    comanda.setFurnizor(furnizor);

    sakila.entity.Client client = ((sakila.entity.Client)ClientComboBox.getSelectedItem());
    comanda.setClient(client);

    Produs produs = ((Produs)ProdusComboBox.getSelectedItem());
    comanda.setProdus(produs);

    comanda.setCantitate(Integer.parseInt(CantitateTextField.getText()));
    comanda.setUnitmas(UnitMasTextField.getText());

    sakila.client.Client.scrie(Functie.CREAZA_COMANDA, comanda);
}

 public static void main(String args[]) {

 java.awt.EventQueue.invokeLater(new Runnable() {

        public void run() {
            new AdaugaComanda().setVisible(true);
        }
    });
}

Maybe someone could help me. Thank you a lot!

Ads
View Answers
Ads









Related Tutorials/Questions & Answers:
Advertisements