0

I've a problem in my program:

There is a few classes

class Info{
private String number;
private Date date;
private String user;
private double sum;
private String nameCurrency;
private double courceOfCurrency;

public void setNumber(String s){
    this.number = s;
}
public void setDate(Date d){
    this.date = d;
}
public void setUser(String user){
    this.user = user;
}
public void setSum(double sum){
    this.sum = sum;
}
public void setNameCurrency(String nameCurrency){
    this.nameCurrency = nameCurrency;
}
public void setCourceOfCurrency(double courceOfCurrency){
    this.courceOfCurrency = courceOfCurrency;
}
public String getNumber(){
    return number;
}
public Date getDate(){
    return date;
}
public String getUser(){
    return user;
}
public double getSum(){
    return sum;
}
public String getNameCurrency(){
    return  nameCurrency;
}
public double getCourceOfCurrency(){
    return courceOfCurrency;
}
}

class Bill extends Info{

private String product;
private double qty;

public void setProduct(String s){
    this.product = s;
}
private void setQty(double qty){
    this.qty = qty;
}

public String getProduct(){
    return product;
}
public double getQty(){
    return qty;
}
}

Main

public class Main {
public static void main(String[] args) {
    JFrame frame = new MainFrame("TestWork");
    frame.setVisible(true);
}
}

At the Class MainFrame:

//something  
DefaultListModel listModel = new DefaultListModel();
    JList list = new JList(listModel);
//sometheing

And Class SecondFrame. There is a few JLabel and JTextfield. question: how to get value from JTextField(SecondFrame) and put him in JList(MainFrame class)?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Ilnar Karimov
  • 339
  • 2
  • 6
  • 19
  • 3
    1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) Please use code formatting for code, input/output & structured documents like HTML or XML. To do that, select the sample and click the `{}` button above the messaged posting/editing form. 3) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson Jun 28 '13 at 09:51
  • 1
    Also see [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice). The logic remains, pass an instance of the class whos instance method you want to access to the class which will access it via a constructor or getter/setter method. Alternatively have a look at the [Singleton design pattern](http://en.wikipedia.org/wiki/Singleton_pattern). Which allows only one instance of a class to exist per app, it allows all classes to access methods within the singleton without the need for passing instances of the class – David Kroukamp Jun 28 '13 at 09:54
  • 1
    For an example of Singleton design see [this](http://stackoverflow.com/questions/17327352/calling-swing-jpanels-from-actionlistener/17327929#17327929) answer (first code snippet), and for passing instance to another class so we can access that classes instance methods check [this](http://stackoverflow.com/questions/17348284/how-to-delete-an-jpanel-object/17353422#17353422) snippet. – David Kroukamp Jun 28 '13 at 09:59
  • seriously thank you. i didn't know – Ilnar Karimov Jun 28 '13 at 10:01
  • @AndrewThompson sorry I only see now that you posted that link too :). – David Kroukamp Jun 28 '13 at 10:02
  • 1
    2 more things: 1) have a read on [Concurrency in Swing](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html). All Swing components should be created/manipulated on the [EDT](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html) via `SwingUtilities.invokeXXX` block. 2) dont extend `JFrame` class unnecessarily create an instance and use that i.e `JFrame frame=new JFrame();` – David Kroukamp Jun 28 '13 at 10:06
  • 1
    @DavidKroukamp No need for apologies since.. a) I edited that comment fairly late once I realized & b) It cannot be mentioned too many times IMO. – Andrew Thompson Jun 28 '13 at 10:37

0 Answers0