Ask Experts Questions for FREE Help !
Ask
    kishan.prajapati's Avatar
    kishan.prajapati Posts: 2, Reputation: 1
    New Member
     
    #1

    Jun 8, 2010, 07:09 AM
    forum to ask java question
    hi guys me working on swing in a project and I'm not understanding how me can get value from jList from one page to another page in jtextfield me using netbean



    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /*
    * SalesOfGoodsGUI.java
    *
    * Created on Jun 7, 2010, 7:19:01 PM
    */
    package learn;

    import javax.swing.JList;

    /**
    *
    * @author Vinay
    */
    public class SalesOfGoodsGUI extends javax.swing.JFrame {

    /** Creates new form SalesOfGoodsGUI */
    public SalesOfGoodsGUI() {
    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() {

    jScrollPane3 = new javax.swing.JScrollPane();
    jTree1 = new javax.swing.JTree();
    jScrollPane4 = new javax.swing.JScrollPane();
    jEditorPane1 = new javax.swing.JEditorPane();
    jCheckBox1 = new javax.swing.JCheckBox();
    jLabel1 = new javax.swing.JLabel();
    SetValueTextField = new javax.swing.JTextField();
    InventoryLabel = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    InventoryList = new javax.swing.JList();
    FareLabel = new javax.swing.JLabel();
    jScrollPane2 = new javax.swing.JScrollPane();
    FareList = new javax.swing.JList();
    SubmitButton = new javax.swing.JButton();
    lblText = new javax.swing.JLabel();
    lblTestValue = new javax.swing.JLabel();
    FareSetLabel = new javax.swing.JLabel();

    jScrollPane3.setViewportView(jTree1);

    jScrollPane4.setViewportView(jEditorPane1);

    jCheckBox1.setText("jCheckBox1");

    jLabel1.setText("jLabel1");

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

    InventoryLabel.setText("Inventory");

    InventoryList.setModel(new javax.swing.AbstractListModel() {
    String[] strings = { "Car", "Byke", "Fruit", "Cold Drink", "Pizza" };
    public int getSize() { return strings.length; }
    public Object getElementAt(int I) { return strings[i]; }
    });
    jScrollPane1.setViewportView(InventoryList);

    FareLabel.setText("Fare");

    FareList.setModel(new javax.swing.AbstractListModel() {
    String[] strings = { "200000", "50000", "50", "12", "30" };
    public int getSize() { return strings.length; }
    public Object getElementAt(int I) { return strings[i]; }
    });
    jScrollPane2.setViewportView(FareList);

    SubmitButton.setText("Submit");
    SubmitButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    SubmitButtonActionPerformed(evt);
    }
    });

    lblTestValue.setText("11111111");

    FareSetLabel.setText("FareSet");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(134, 134, 134)
    .addComponent(SubmitButton)
    .addContainerGap(566, Short.MAX_VALUE))
    .addGroup(layout.createSequentialGroup()
    .addGap(68, 68, 68)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING, false)
    .addGroup(layout.createSequentialGroup()
    .addComponent(FareLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(50, 50, 50)
    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(layout.createSequentialGroup()
    .addComponent(InventoryLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 501, Short.MAX_VALUE)
    .addComponent(lblText)
    .addGap(22, 22, 22))
    .addGroup(layout.createSequentialGroup()
    .addGap(166, 166, 166)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addComponent(FareSetLabel)
    .addComponent(lblTestValue))
    .addGap(309, 309, 309))))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(InventoryLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGap(33, 33, 33)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addComponent(lblTestValue)
    .addGap(57, 57, 57)
    .addComponent(FareSetLabel)
    .addContainerGap())
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(15, 15, 15)
    .addComponent(lblText))
    .addComponent(FareLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 49, Short.MAX_VALUE)
    .addComponent(SubmitButton)
    .addGap(115, 115, 115))))
    );

    pack();
    }// </editor-fold>

    private void SubmitButtonActionPerformed(java.awt.event.ActionE vent evt) {

    ShowPage page = new ShowPage();
    Object strInventory [] = this.InventoryList.getSelectedValues();
    String strValue1 = "";
    for (int I = 0; I < strInventory.length; I++) {
    System.out.println(strInventory[i].toString());

    if(I==0){
    strValue1 = strInventory[i].toString();
    }else{
    strValue1 += "," + strInventory[i].toString();
    }
    }

    page.setVisible(true);
    this.lblTestValue.setText(strValue1);
    //page.getContentPane().add(InventoryLabel);
    page.getContentPane().add(InventoryLabel);
    page.getContentPane().add(lblTestValue);


    Object strFare [] = this.FareList.getSelectedValues();
    String strValue2 = "";
    for (int I = 0; I < strFare.length; I++) {
    System.out.println(strFare[i].toString());

    if(I==0){
    strValue2 = strFare[i].toString();
    }else{
    strValue2 += "," + strFare[i].toString();
    }

    page.setVisible(true);
    this.FareSetLabel.setText(strValue2);
    page.getContentPane().add(FareLabel);
    page.getContentPane().add(FareSetLabel);
    //


    //int j = FareList.getSelectedIndex();
    // SetValueTextField.setText( j >= 0 ? StrValue2.get( j ) : "" );


    /*FareList.addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    int j = FareList.getSelectedIndex();
    SetValueTextField.setText( j >= 0 ? strValue2.get( j ) : "" );
    }
    });
    return new JScrollPane( SetValueTextField ); */




    }
    //
    //
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {
    new SalesOfGoodsGUI().setVisible(true);
    }
    });
    }
    // Variables declaration - do not modify
    private javax.swing.JLabel FareLabel;
    private javax.swing.JList FareList;
    private javax.swing.JLabel FareSetLabel;
    private javax.swing.JLabel InventoryLabel;
    private javax.swing.JList InventoryList;
    private javax.swing.JTextField SetValueTextField;
    private javax.swing.JButton SubmitButton;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTree jTree1;
    private javax.swing.JLabel lblTestValue;
    private javax.swing.JLabel lblText;
    // End of variables declaration
    }
    kishan.prajapati's Avatar
    kishan.prajapati Posts: 2, Reputation: 1
    New Member
     
    #2

    Jun 8, 2010, 07:18 AM

    hi guys me working on swing in a project and I'm not understanding how me can get value from jList from one page to another page in jtextfield me using netbean



    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /*
    * SalesOfGoodsGUI.java
    *
    * Created on Jun 7, 2010, 7:19:01 PM
    */
    package learn;

    import javax.swing.JList;

    /**
    *
    * @author Vinay
    */
    public class SalesOfGoodsGUI extends javax.swing.JFrame {

    /** Creates new form SalesOfGoodsGUI */
    public SalesOfGoodsGUI() {
    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() {

    jScrollPane3 = new javax.swing.JScrollPane();
    jTree1 = new javax.swing.JTree();
    jScrollPane4 = new javax.swing.JScrollPane();
    jEditorPane1 = new javax.swing.JEditorPane();
    jCheckBox1 = new javax.swing.JCheckBox();
    jLabel1 = new javax.swing.JLabel();
    SetValueTextField = new javax.swing.JTextField();
    InventoryLabel = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    InventoryList = new javax.swing.JList();
    FareLabel = new javax.swing.JLabel();
    jScrollPane2 = new javax.swing.JScrollPane();
    FareList = new javax.swing.JList();
    SubmitButton = new javax.swing.JButton();
    lblText = new javax.swing.JLabel();
    lblTestValue = new javax.swing.JLabel();
    FareSetLabel = new javax.swing.JLabel();

    jScrollPane3.setViewportView(jTree1);

    jScrollPane4.setViewportView(jEditorPane1);

    jCheckBox1.setText("jCheckBox1");

    jLabel1.setText("jLabel1");

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

    InventoryLabel.setText("Inventory");

    InventoryList.setModel(new javax.swing.AbstractListModel() {
    String[] strings = { "Car", "Byke", "Fruit", "Cold Drink", "Pizza" };
    public int getSize() { return strings.length; }
    public Object getElementAt(int I) { return strings[i]; }
    });
    jScrollPane1.setViewportView(InventoryList);

    FareLabel.setText("Fare");

    FareList.setModel(new javax.swing.AbstractListModel() {
    String[] strings = { "200000", "50000", "50", "12", "30" };
    public int getSize() { return strings.length; }
    public Object getElementAt(int I) { return strings[i]; }
    });
    jScrollPane2.setViewportView(FareList);

    SubmitButton.setText("Submit");
    SubmitButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    SubmitButtonActionPerformed(evt);
    }
    });

    lblTestValue.setText("11111111");

    FareSetLabel.setText("FareSet");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(134, 134, 134)
    .addComponent(SubmitButton)
    .addContainerGap(566, Short.MAX_VALUE))
    .addGroup(layout.createSequentialGroup()
    .addGap(68, 68, 68)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING, false)
    .addGroup(layout.createSequentialGroup()
    .addComponent(FareLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(50, 50, 50)
    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(layout.createSequentialGroup()
    .addComponent(InventoryLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 501, Short.MAX_VALUE)
    .addComponent(lblText)
    .addGap(22, 22, 22))
    .addGroup(layout.createSequentialGroup()
    .addGap(166, 166, 166)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addComponent(FareSetLabel)
    .addComponent(lblTestValue))
    .addGap(309, 309, 309))))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(InventoryLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGap(33, 33, 33)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addComponent(lblTestValue)
    .addGap(57, 57, 57)
    .addComponent(FareSetLabel)
    .addContainerGap())
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(15, 15, 15)
    .addComponent(lblText))
    .addComponent(FareLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 49, Short.MAX_VALUE)
    .addComponent(SubmitButton)
    .addGap(115, 115, 115))))
    );

    pack();
    }// </editor-fold>

    private void SubmitButtonActionPerformed(java.awt.event.ActionE vent evt) {

    ShowPage page = new ShowPage();
    Object strInventory [] = this.InventoryList.getSelectedValues();
    String strValue1 = "";
    for (int I = 0; I < strInventory.length; I++) {
    System.out.println(strInventory[i].toString());

    if(I==0){
    strValue1 = strInventory[i].toString();
    }else{
    strValue1 += "," + strInventory[i].toString();
    }
    }

    page.setVisible(true);
    this.lblTestValue.setText(strValue1);
    //page.getContentPane().add(InventoryLabel);
    page.getContentPane().add(InventoryLabel);
    page.getContentPane().add(lblTestValue);


    Object strFare [] = this.FareList.getSelectedValues();
    String strValue2 = "";
    for (int I = 0; I < strFare.length; I++) {
    System.out.println(strFare[i].toString());

    if(I==0){
    strValue2 = strFare[i].toString();
    }else{
    strValue2 += "," + strFare[i].toString();
    }

    page.setVisible(true);
    this.FareSetLabel.setText(strValue2);
    page.getContentPane().add(FareLabel);
    page.getContentPane().add(FareSetLabel);
    //


    //int j = FareList.getSelectedIndex();
    // SetValueTextField.setText( j >= 0 ? StrValue2.get( j ) : "" );


    /*FareList.addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    int j = FareList.getSelectedIndex();
    SetValueTextField.setText( j >= 0 ? strValue2.get( j ) : "" );
    }
    });
    return new JScrollPane( SetValueTextField ); */




    }
    //
    //
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {
    new SalesOfGoodsGUI().setVisible(true);
    }
    });
    }
    // Variables declaration - do not modify
    private javax.swing.JLabel FareLabel;
    private javax.swing.JList FareList;
    private javax.swing.JLabel FareSetLabel;
    private javax.swing.JLabel InventoryLabel;
    private javax.swing.JList InventoryList;
    private javax.swing.JTextField SetValueTextField;
    private javax.swing.JButton SubmitButton;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTree jTree1;
    private javax.swing.JLabel lblTestValue;
    private javax.swing.JLabel lblText;
    // End of variables declaration
    }
    ___________________________
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /*
    * ShowPage.java
    *
    * Created on Jun 8, 2010, 10:21:47 AM
    */

    package learn;

    /**
    *
    * @author Vinay
    */
    public class ShowPage extends javax.swing.JFrame {

    /** Creates new form ShowPage */
    public ShowPage() {

    initComponents();
    setDefaultCloseOperation(javax.swing.
    WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("Welcome");
    setSize(400, 200);

    }

    /** 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() {

    SetValueTextField = new javax.swing.JTextField();

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(87, 87, 87)
    .addComponent(SetValueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(112, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(88, 88, 88)
    .addComponent(SetValueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(138, Short.MAX_VALUE))
    );

    pack();
    }// </editor-fold>

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new ShowPage().setVisible(true);
    }
    });
    }

    // Variables declaration - do not modify
    private javax.swing.JTextField SetValueTextField;
    // End of variables declaration

    }
    ___________________
    my no is 9015116841

    and EmailId

    [email protected]

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Three year old won't answer a question, he only repeats the question... any thoughts? [ 7 Answers ]

I have three children who have never had any learning troubles however I babysit 2 kids each day that seem to be a little socially awkward. The oldest (age 5 1/2) won't look me in the eye and can't follow a multi-step instruction. The younger (age 3) has never been able to answer a question I ask...

Java Help! [ 7 Answers ]

Hi Experts, I'm not sure if I'm posting this in the right category, but I sure hope someone can still help me. I'm not able to view Java applets. I've downloaded the most recent version of JVM. I have version 1.4.1. I've tried changing some settings (like enabling Java in my internet...


View more questions Search