在JList中写一些东西 [英] Writing something in JList
问题描述
JList
,现在我想添加一些内容。我是这样做的... private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
Dodaj_Przedmiot dodaj_przedmiot = new Dodaj_Przedmiot(null,true);
dodaj_przedmiot.setVisible(true);
SterowanieBazy instance = SterowanieBazy.getInstance();
Zmienne_pomocnicze zp = new Zmienne_pomocnicze();
String przedmiot = zp.getPrzechowaj();
instance.dodajPrzedmiot(przedmiot);
String przedm [] = instance.zwrocPrzedmioty();
jList1.setListData(przedm);
}
我要在该列表中写的是我从jDialogForm收集的内容: dodaj_przedmiot
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
String sciezka = jTextField1.getText();
if(sciezka.length()> 0)
{
Zmienne_pomocnicze zp = new Zmienne_pomocnicze();
zp.setPrzechowaj(sciezka);
}
this.setVisible(false);
}
我收集尝试使用此类复制该日期
公共类Zmienne_pomocnicze {
public String n;
public int a;
public void setPrzechowaj(String neew)
{
n = neew;
}
public String getPrzechowaj()
{
return n;
}
}
我会很感激任何想法如何使它工作。
这有点难以理解,但从我收集到的,你正在使用你的 Zmienne_pomocnicze
两个地方的课程,他们两个似乎什么都不做。
首先,在 jButton2ActionPerformed
中实例化一个新的 Zmienne_pomocnicze
并尝试使用 getPrzechowaj
方法从中获取数据。这将返回 n
,但是当您刚刚实例化实例时, n
是 null
。由于我无法从以下代码的方法名称推断,我无法弄清楚你想对这些数据做什么,但这个动作肯定不是你想要做的。
在第二种情况下, jButton1ActionPerformed
从文本字段中获取值,然后测试其有效性(legnth大于0)。如果验证通过,则您创建一个新的 Zmienne_pomocnicze
,使用文本字段值调用 setPrezechowaj
然后让新的对象超出范围。同样,这肯定不是预期的效果。
看看你的程序流程应该是什么,即触发哪个按钮<$ c会很有趣$ c> jButton [12] ActionPerformed 方法以及您希望它们如何互动。
hey i have another problem. I created JList
in my main window and now i want to add something to it. I do it this way...
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
Dodaj_Przedmiot dodaj_przedmiot = new Dodaj_Przedmiot(null, true);
dodaj_przedmiot.setVisible(true);
SterowanieBazy instance = SterowanieBazy.getInstance();
Zmienne_pomocnicze zp = new Zmienne_pomocnicze();
String przedmiot = zp.getPrzechowaj();
instance.dodajPrzedmiot(przedmiot);
String przedm[] = instance.zwrocPrzedmioty();
jList1.setListData(przedm);
}
what i want to write in that list is what i collect from my jDialogForm: dodaj_przedmiot
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
String sciezka = jTextField1.getText();
if (sciezka.length() > 0)
{
Zmienne_pomocnicze zp = new Zmienne_pomocnicze();
zp.setPrzechowaj(sciezka);
}
this.setVisible(false);
}
and i collect try to copy that date using this class
public class Zmienne_pomocnicze {
public String n;
public int a;
public void setPrzechowaj (String neew)
{
n = neew;
}
public String getPrzechowaj ()
{
return n;
}
}
i would be grateful for any ideas how to make it work.
This is somewhat difficult to follow, but from what I gather, you are using your Zmienne_pomocnicze
class in two places, and both of them seem to do nothing.
First, in jButton2ActionPerformed
you instantiate a new Zmienne_pomocnicze
and try to get the data from it using the getPrzechowaj
method. This will return n
, but as you have just instantiated the instance, n
is null
. As I cant infer from the method names of the following code, I cant figure out what you want to do with that data, but this action is most certainly not what you want to do.
In the second case, jButton1ActionPerformed
takes the value from the text field and then test for validity (legnth is greater than 0). If the validation passes, you then create a new Zmienne_pomocnicze
, call setPrezechowaj
with the text field value and then let the new object fall out of scope. Again, this is certainly not the desired effect.
It would be interesting to see what the flow of your program is supposed to be, ie what button triggers which jButton[12]ActionPerformed
methods and how you expect them to interact.
这篇关于在JList中写一些东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!