欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaGUI使用標(biāo)簽與按鈕方法詳解

 更新時(shí)間:2023年03月03日 11:22:32   作者:頭禿小程  
這篇文章主要介紹了JavaGUI使用標(biāo)簽與按鈕方法,前段時(shí)間學(xué)了GUI,總體上概念還是有點(diǎn)模糊,于是決定花點(diǎn)時(shí)間簡(jiǎn)單整理下。先簡(jiǎn)單介紹一下GUI,GUI就是圖形用戶界面

1.標(biāo)簽

  • 類(lèi):JLabel
  • 作用:顯示文本或者提示信息

構(gòu)造函數(shù):

  • new JLabel();
  • new JLabel(Icon icon);//設(shè)置圖標(biāo)
  • new JLabel(Icon icon,int aligment);//設(shè)置圖標(biāo)+水平對(duì)齊方式
  • new JLabel(String str,int aligment);//設(shè)置文本+水平對(duì)齊方式
  • new JLabel(String str,Icon icon,int aligment);//設(shè)置文本+圖標(biāo)+水平對(duì)齊方式

示例:

import javax.swing.*;
public class Jlabel {
    public static void main(String[] args){
        JFrame jf=new JFrame("JLabel");
        jf.setBounds(400,300,200,300);
        JLabel jl=new JLabel("賬戶:",SwingConstants.LEFT);
        jf.add(jl);
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

2.按鈕

類(lèi):JButton

構(gòu)造方法:

  • new JButton();
  • new JButton(String text);//指定文字
  • new JButton(Icon icon);//指定圖標(biāo)
  • new JButton(String str,Icon icon);//指定文字+圖標(biāo)

其他方法:

.setTooltipText(String text); //設(shè)置提示文字
.setBordePainted();//設(shè)置邊界是否顯示
.setEnabled();//設(shè)置按鈕是否可用

示例1(按鈕可用,有邊界-默認(rèn)):

import javax.swing.*;
import java.awt.*;
public class Jbutton {
    public static void main(String[] args){
        JFrame jf=new JFrame("JLabel");
        jf.setBounds(400,300,200,300);
        jf.setLayout(new FlowLayout());
        JButton jb=new JButton("按鈕1");
        jb.setEnabled(true);
        jf.add(jb);
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

示例2(按鈕不可用):

import javax.swing.*;
import java.awt.*;
public class Jbutton {
    public static void main(String[] args){
        JFrame jf=new JFrame("JLabel");
        jf.setBounds(400,300,200,300);
        jf.setLayout(new FlowLayout());
        JButton jb=new JButton("按鈕1");
        jb.setEnabled(false);
        jf.add(jb);
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

示例3(無(wú)邊界):

import javax.swing.*;
import java.awt.*;
public class Jbutton {
    public static void main(String[] args){
        JFrame jf=new JFrame("JLabel");
        jf.setBounds(400,300,200,300);
        jf.setLayout(new FlowLayout());
        JButton jb=new JButton("按鈕1");
        jb.setEnabled(true);
        jb.setBorderPainted(false);
        jf.add(jb);
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

到此這篇關(guān)于JavaGUI使用標(biāo)簽與按鈕方法詳解的文章就介紹到這了,更多相關(guān)JavaGUI標(biāo)簽與按鈕內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論