我不完全确定你在问什么,但我会尽我所能去帮助。
假设你有两个标签:(!“世界,你好”)
JLabel label1 = new JLabel l("Hello!");
JLabel label2 = new JLabel l("Hello world!");
如果你现在要LABEL1的(“你好”)中的内容设置成标签2,你可以做到以下几点:
label2.setText(label1.getText());
由于您在问题描述中使用了“计算”一词,因此我假设您的标签包含您想要进行计算的数字。
您可以将标签方法.getText()与Integer.parseInt(String s)或Double.parseInt(String s)结合使用,具体取决于您拥有的值的类型。例如:
JLabel label1 = new JLabel l("5");
JLabel label2 = new JLabel l("");
int i = Integer.parseInt(label1.getText()); // takes the string from label1 and transforms it to an integer using the parseInt() method.
// i now has the value 5
i = i*5; // an example of some calculation you mentioned you wanted to do
label2.setText(i +""); // transforms the integer value to string and sets it into label2
我不知道我是否正确理解您的问题,所以请详细说明您是否需要其他帮助:)。
您需要提供更多的细节。 JLabels不计算任何东西。描述你已有的信息,你想要的结果,以及你目前得到的结果。 – VGR
@VGR I上面包含更多细节^ –
每次价格或折扣因素发生变化时,您都必须重复计算。这是无法避免的。 – VGR