Java_log2000_awt&swing编程1

为你的界面上色等

关键词:awt; swing; java gui;

1。设置普通按钮等的颜色

假设有一个界面类

public class xxxx{
    ...
    private JButton connectButton;
    private JPanel jPanelNorth1;
    ...
}

构造方法

public xxxx() {
    ...
    connectButton = new JButton("connect");
    jPanelNorth1 = new JPanel();
    ...
    //为connectButton上色
    jPanelNorth1.add(connectButton); 
    connectButton.setBackground(new Color(30, 30, 30));//背景颜色
    connectButton.setForeground(new Color(32, 178, 170));//文字颜色
    connectButton.setBorder(BorderFactory.createLineBorder(new Color(34, 139, 34)));//设置面板边框颜色
}

2.1。 设置弹出窗口的ui

//弹窗ui
    UIManager UI=new UIManager();
    UI.put("OptionPane.background", new Color(30, 30, 30));
    UI.put("Panel.background", new Color(30, 30, 30));
    UI.put("Button.background", new Color(30, 30, 30));

2.2。 设置弹出窗口的文字和按键自定义

public class xxxx{
    ...
    public Object[] red_options = {"<html><font color="+"RED"+">OK</font></html>"};
    ...
}
...
...
// 单击连接按钮时事件
connectButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    int port;
    if (isConnected) {
        JOptionPane.showOptionDialog(clientFrame,"<html><font color="+"red"+" size="+"6"+">already connected!</font></html>","error",JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, red_options, red_options[0]);
        return;
    }
    ...
    ...

3 。窗口标题

clientFrame = new JFrame("client terminal");

visitor tracker
访客追踪插件


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值