I am trying to change Jlabel
text which is added to another label if condition is met. But updated text is overlapping on previous text.
public class FGtest extends JFrame {
public FGtest() {
JLabel fg_layout = new JLabel();
ImageIcon fgImageIcon = new ImageIcon(getClass().getResource("images/overall layout.JPG"));
fg_layout.setIcon(fgImageIcon);
Gradient gradient_layout = new Gradient();
gradient_layout.add(fg_layout);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new FGtest();
}
});
}
@SuppressWarnings("serial")
class Gradient extends JPanel {
private String wpl_test = "";
private String wpl1_status = "";
private String wpl2_status = "";
private Jedis jedis;
public Gradient() {
new Timer(1000, new TimerListener()).start();
}
private class TimerListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent ae) {
try {
jedis = new Jedis("192.168.0.140");
wpl_test = jedis.get("wpl_test");
wpl1_status = jedis.get("wpl1_status");
wpl2_status = jedis.get("wpl2_status");
repaint();
} catch (Exception e) {
}
}
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2D = (Graphics2D) g;
AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.7 f);
g2D.setComposite(alphaComposite);
//-------wpl test----
JLabel label11 = new JLabel();
label11.setFont(new Font("Times New Roman", Font.BOLD, 30));
label11.setBounds(800, 229, 300, 100);
label11.setForeground(Color.orange);
fg_layout.add(label11);
if (wpl_test.equals("1")) {
// label2.setVisible(false);
// fg_layout.remove(label2);
// label2.setBounds(800,229,0,0);
// JLabel label1 = new JLabel();
// label1.setFont(new Font("Times New Roman",Font.BOLD,30));
// label1.setBounds(800,229,300,100);
// label1.setText("wpl 1:1");
// label1.setForeground(Color.orange);
// fg_layout.add(label1);
label11.setText("wpl 1:1");
if (wpl1_status.equals("pass")) {
g2D.setColor(Color.green);
int x1[] = {
610,
1057,
1017,
520
};
int y1[] = {
120,
350,
485,
220
};
g2D.fillPolygon(x1, y1, 4);
} else if (wpl1_status.equals("fail")) {
g2D.setColor(Color.red);
int x1[] = {
610,
1057,
1017,
520
};
int y1[] = {
120,
350,
485,
220
};
g2D.fillPolygon(x1, y1, 4);
}
} else if (wpl_test.equals("2")) {
// label1.setVisible(false);
// fg_layout.remove(label11);
// label1.setBounds(800,229,0,0);
// JLabel label2 = new JLabel();
// label2.setFont(new Font("Times New Roman",Font.BOLD,30));
// label2.setBounds(800,229,300,100);
// label2.setText("wpl as such");
// label2.setForeground(Color.orange);
// fg_layout.add(label2);
label11.setText("wpl as such");
if (wpl2_status.equals("pass")) {
g2D.setColor(Color.green);
int x1[] = {
610,
1057,
1017,
520
};
int y1[] = {
120,
350,
485,
220
};
g2D.fillPolygon(x1, y1, 4);
} else if (wpl2_status.equals("fail")) {
g2D.setColor(Color.red);
int x1[] = {
610,
1057,
1017,
520
};
int y1[] = {
120,
350,
485,
220
};
g2D.fillPolygon(x1, y1, 4);
}
}
}
}
}