我是Java语言的新手,我开始自己和互联网制作一个程序。现在我有这个:
package com.butoane;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class App {
private JButton apasaAiciButton;
private JPanel Dunno;
private JButton apoiaici;
private JTextArea text1;
private JProgressBar progressBar1;
private JTextArea text2;
public App() {
String a = "H";
String b = "e";
String y = "Ce faci sefule??";
final String[] d = {"x"};
final String[] f = {"D"};
final int[] c = {0};
apasaAiciButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//apoiaici.setEnabled(true);
//apasaAiciButton.setEnabled(false);
text1.append(a);
progressBar1.setValue(c[0] +1);
c[0] = c[0] +1;
}
});
apoiaici.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//apoiaici.setEnabled(false);
//apasaAiciButton.setEnabled(true);
apasaAiciButton.setText("Apasa iar aici");
text1.append(b);
progressBar1.setValue(c[0] +1);
c[0] = c[0] +1;
}
});
}
public static void main(String[] args) {
JFrame frame = new JFrame("App");
frame.setContentPane(new App().Dunno);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
我想要做的是在进度条为100%时向text2添加功能。 例如:当progressbar1为100%时,text2将文本设置为"你做到了!" 。我该怎么做?
FYK:我看过有关JProgressBar和JTextArea的oracle文档,我无法理解。
答案 0 :(得分:0)
进度条是否有效? 如果它有效,那么只需添加。
//the max value of the progress bar == actual value
if (progressBar1.getMaximum() == progressBar1.getValue() {
text2.append("You did it!");
}
答案 1 :(得分:0)
您的代码将抛出NullPointerException,因为您没有初始化任何小部件。向您的进度条添加一个监听器(假设您正在使用Java 8 +)
A<-ggplot(data = subset(DF,site=="A"), aes(x = SWC, y = LE)) +
geom_smooth(method = "lm", se=FALSE, color="black", formula = y ~ x) +
geom_point()
B<-ggplot(data = subset(DF,site=="B"), aes(x = SWC, y = LE)) +
geom_smooth(method = "lm", se=FALSE, color="black", formula = y ~ x) +
geom_point()
C<-ggplot(data = subset(DF,site=="C"), aes(x = SWC, y = LE)) +
geom_smooth(method = "lm", se=FALSE, color="black", formula = y ~ x) +
geom_point()
D<-ggplot(data = subset(DF,site=="D"), aes(x = SWC, y = LE)) +
geom_smooth(method = "lm", se=FALSE, color="black", formula = y ~ x) +
geom_point()
E<-ggplot(data = subset(DF,site=="E"), aes(x = SWC, y = LE)) +
geom_smooth(method = "lm", se=FALSE, color="black", formula = y ~ x) +
geom_point()
Blank<-ggplot()
multiplot(Blank, A, B, C, D, E, cols=3)