如何使用 java 中的链接更改 JLABEL 的颜色?
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class XXX extends JFrame {
XXX(){
final JLabel lab1=new JLabel("Username:");
final JTextField text1=new JTextField(20);
lab1.setBounds(20,140,65,20);
text1.setBounds(85,141,185,20);
add(lab1);
add(text1);
lab1.setForeground(Color.white);
final JLabel lab2=new JLabel("Password:");
final JPasswordField text2=new JPasswordField(20);
lab2.setBounds(20,165,65,20);
text2.setBounds(85,166,185,20);
add(lab2);
add(text2);
lab2.setForeground(Color.white);
final JButton a=new JButton("Sign In");
a.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//Code
}
});
a.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent me) {
a.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
public void mouseExited(MouseEvent me) {
a.setCursor(Cursor.getDefaultCursor());
}
public void mouseClicked(MouseEvent me)
{
a.setEnabled(false);
text1.setEditable(false);
text2.setEditable(false);
try {
}
catch(Exception e) {
System.out.println(e);
}
}
});
a.setBounds(85,192,80,20);
add(a);
final String strURL = "http://www.yahoo.com";
final JLabel lab3 = new JLabel("<html><a href=\" " + strURL + "\">Register</a></html>");
lab3.setBounds(170,192,52,20);
add(lab3);
lab3.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent me) {
lab3.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
public void mouseExited(MouseEvent me) {
lab3.setCursor(Cursor.getDefaultCursor());
}
public void mouseClicked(MouseEvent me)
{
text2.setEditable(false);
try {
}
catch(Exception e) {
System.out.println(e);
}
}
});
final JLabel map = new JLabel(new ImageIcon(getClass().getResource("XXXBG.png")));
map.setBounds(0,0,300,250);
add(map);
setTitle("XXX");
setSize(300,250);
setResizable(false);
setCursor(DEFAULT_CURSOR);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(8, 8);
setLayout(null);
toFront();
setVisible(true);
}
public static void main(String[] args)
{
new XXX();
}
}
如您所见,我无法更改 JLABEL lab3 的前景色。如果可能的话,我还想改变 jframe 的边框颜色。有人可以帮忙吗?