我不完全確定你在問什麼,但我會盡我所能去幫助。
假設你有兩個標籤:(!「世界,你好」)
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