欧美free性护士vide0shd,老熟女,一区二区三区,久久久久夜夜夜精品国产,久久久久久综合网天天,欧美成人护士h版

首頁綜合 正文
目錄

柚子快報(bào)激活碼778899分享:開發(fā)語言 JAVA中的GUI

柚子快報(bào)激活碼778899分享:開發(fā)語言 JAVA中的GUI

http://yzkb.51969.com/

目錄

?一.GUI的概念

1.1基本概念

1.2GUI的特點(diǎn)

1.3Swing的概念

1.4GUI中的容器組件

二.常用容器

2.1JFrame

2.2JFrame中常用的方法

?2.3JPanel

三.GUI面板的布局

3.1流式布局

?3.2邊界布局

3.3網(wǎng)格布局

四.文本框

4.1JLabe

4.2JTextField

4.4 多行文本框(JTextArea)

?4.5按鈕

五.菜單

六.事件處理

?一.GUI的概念

1.1基本概念

GUI是Graphical User Interface(圖形用戶界面)的縮寫,指的是通過圖形方式顯示和操作的用戶界面。它提供了一種直觀、可視化的方式,讓用戶可以通過鼠標(biāo)、鍵盤或觸摸等輸入設(shè)備與計(jì)算機(jī)進(jìn)行交互。

GUI的設(shè)計(jì)目的是簡化用戶與計(jì)算機(jī)系統(tǒng)之間的交互過程,使用戶能夠更輕松、高效地完成各種任務(wù)。傳統(tǒng)的命令行界面(CLI)需要用戶記憶和輸入命令,而GUI則通過圖形元素如窗口、按鈕、菜單、對(duì)話框等來呈現(xiàn)信息和提供操作選項(xiàng),使用戶可以通過直接點(diǎn)擊、拖拽、輸入等方式與計(jì)算機(jī)進(jìn)行交互。

1.2GUI的特點(diǎn)

視覺化:GUI使用圖形元素和視覺效果來代表應(yīng)用程序的功能、數(shù)據(jù)和操作,以便用戶能夠直觀地理解和操作。 交互性:GUI允許用戶通過鼠標(biāo)、鍵盤或觸摸等輸入設(shè)備進(jìn)行交互操作,包括點(diǎn)擊、拖拽、輸入等,使用戶能夠主動(dòng)地與計(jì)算機(jī)進(jìn)行溝通和反饋。 易用性:GUI設(shè)計(jì)注重用戶體驗(yàn),追求簡潔、易于理解和操作的界面,減少用戶的學(xué)習(xí)成本和操作困難。 多任務(wù)支持:GUI允許多個(gè)應(yīng)用程序同時(shí)運(yùn)行在屏幕上的不同窗口中,并提供了任務(wù)切換和管理的功能,方便用戶在不同應(yīng)用程序之間進(jìn)行切換和操作。 可視化編程:基于GUI的開發(fā)工具和框架使開發(fā)人員能夠使用可視化方式設(shè)計(jì)和構(gòu)建應(yīng)用程序界面,簡化開發(fā)流程。

1.3Swing的概念

Swing是純Java組件,使得應(yīng)用程序在不同的平臺(tái)上運(yùn)行時(shí)具有相同外觀和相同 的行為。

Swing中的大部分組件類位于javax.swing包中.

Swing中的組件非常豐富,支持很多功能強(qiáng)大的組件。

1.4GUI中的容器組件

Java的圖形用戶界面的基本組成部分是組件,組件是一個(gè)以圖形化的方式 顯示在屏幕上并能與用戶進(jìn)行交互的對(duì)象; 組件不能獨(dú)立地顯示出來,必須將組件放在一定的容器(container)中才 可以顯示出來。

容器可以容納多個(gè)組件,通過調(diào)用容器的add(Component comp)方法 向容器中添加組件。

窗口(Frame)和面板(Panel)是最常用的兩個(gè)容器。

二.常用容器

2.1JFrame

JFrame是一個(gè)用于創(chuàng)建窗口和應(yīng)用程序框架的類。它是javax.swing包中的一部分,提供了一些基本功能,如窗口管理、布局管理和事件處理等。

JFrame類代表了一個(gè)頂級(jí)窗口,可以包含其他GUI組件,如按鈕、文本框、標(biāo)簽等。通過使用JFrame,可以創(chuàng)建具有標(biāo)題欄、最大化、最小化、關(guān)閉按鈕等標(biāo)準(zhǔn)窗口功能的應(yīng)用程序。

創(chuàng)建了一個(gè)繼承自JFrame的自定義類MyFrame。在構(gòu)造函數(shù)中,設(shè)置了窗口的標(biāo)題、大小、默認(rèn)的關(guān)閉操作,并將窗口設(shè)置為可見。最后,在main方法中創(chuàng)建了MyFrame對(duì)象,即實(shí)例化了窗口并顯示出來。

除了基本的窗口和應(yīng)用程序框架功能外,JFrame還提供了許多方法用于添加和管理其他GUI組件、設(shè)置窗口屬性和處理事件等。通過靈活運(yùn)用JFrame以及其他Swing組件,可以構(gòu)建出功能強(qiáng)大、交互友好的Java圖形界面應(yīng)用程序。

下面是GUI窗口的簡單創(chuàng)建:

import javax.swing.*;

import java.awt.*;

public class MyJFrame extends JFrame {

public MyJFrame() throws HeadlessException {

this.setSize(500,500);//設(shè)置窗口大小

this.setLocationRelativeTo(null);//設(shè)置水平居中

this.setVisible(true);//啟動(dòng)窗口

}

public static void main(String[] args) {

new MyJFrame();

}

}

代碼執(zhí)行的結(jié)果為:

2.2JFrame中常用的方法

setTitle(String title):設(shè)置窗口標(biāo)題。 setSize(int width, int height):設(shè)置窗口的寬度和高度。 setLocation(int x, int y):設(shè)置窗口在屏幕上的位置。 setResizable(boolean resizable):設(shè)置窗口是否可調(diào)整大小。 setDefaultCloseOperation(int operation):設(shè)置窗口關(guān)閉時(shí)的操作,常用的操作有:

JFrame.EXIT_ON_CLOSE:退出程序。JFrame.HIDE_ON_CLOSE:隱藏窗口。JFrame.DISPOSE_ON_CLOSE:釋放窗口占用的資源。 setVisible(boolean visible):設(shè)置窗口是否可見。 getContentPane():獲取窗口的內(nèi)容面板,用于添加和管理其他GUI組件。 add(Component comp):將指定的組件添加到窗口的內(nèi)容面板中。 setLayout(LayoutManager manager):設(shè)置窗口的布局管理器,用于管理組件的位置和大小。 pack():自動(dòng)調(diào)整窗口的大小,以適應(yīng)其中包含的所有組件。 setDefaultCloseOperation(int operation):設(shè)置窗口關(guān)閉時(shí)的操作。

這些方法在實(shí)際中的運(yùn)用:

public class MyJFrame extends JFrame {

public MyJFrame() throws HeadlessException {

this.setTitle("窗口標(biāo)題");//設(shè)置窗口標(biāo)題

this.setSize(500,500);//設(shè)置窗口大小

//this.setLocation(300,400);//設(shè)置窗口在界面的顯示位置

this.setLocationRelativeTo(null);//設(shè)置窗戶口顯示位置水平居中

this.setResizable(false);//設(shè)置之后禁止設(shè)置窗口大小

//this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);//DO_NOTHING_ON_CLOSE設(shè)置之后無法自己關(guān)閉界面

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設(shè)置之后有了關(guān)閉選項(xiàng)

this.setVisible(true);//啟動(dòng)窗口

}

public static void main(String[] args) {

new MyJFrame();

}

}

代碼實(shí)現(xiàn)結(jié)果為:

?2.3JPanel

JPanel是Java GUI編程中常用的容器類,它位于javax.swing包中,用于組織和管理其他GUI組件。JPanel可以看作是一個(gè)空白的面板,你可以將其他組件添加到其中,并對(duì)其進(jìn)行布局、設(shè)置風(fēng)格和添加事件監(jiān)聽等操作。

以下是JPanel中常用的方法:

add(Component comp):將指定的組件添加到面板中。 remove(Component comp):從面板中移除指定的組件。 setLayout(LayoutManager manager):設(shè)置面板的布局管理器,用于管理組件的位置和大小。 setBackground(Color color):設(shè)置面板的背景顏色。 setPreferredSize(Dimension size):設(shè)置面板的首選大小。 setBorder(Border border):設(shè)置面板的邊框。 setVisible(boolean visible):設(shè)置面板是否可見。 validate():重新驗(yàn)證面板及其所有子組件的布局。 repaint():請(qǐng)求重繪面板及其所有子組件。 getComponent(int index):獲取面板指定位置索引處的組件。 getComponents():獲取面板中的所有組件。 getLayout():獲取面板的布局管理器。

JPanel提供了一種靈活的方式來組織和管理GUI界面中的組件。它可以嵌套在其他容器中,例如JFrame、JDialog等。通過使用多個(gè)JPanel,可以實(shí)現(xiàn)復(fù)雜的布局結(jié)構(gòu)和層次化的容器組織。

三.GUI面板的布局

3.1流式布局

JPanel默認(rèn)的就是流式布局。

流式布局的樣式為:

以下代碼是在流式布局中添加組件的代碼:

public class MyJFrame extends JFrame {

public MyJFrame() throws HeadlessException {

this.setTitle("窗口標(biāo)題");//設(shè)置窗口標(biāo)題

this.setSize(500,500);//設(shè)置窗口大小

//this.setLocation(300,400);//設(shè)置窗口在界面的顯示位置

this.setLocationRelativeTo(null);//設(shè)置窗戶口顯示位置水平居中

this.setResizable(false);//設(shè)置之后禁止設(shè)置窗口大小

//this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);//DO_NOTHING_ON_CLOSE設(shè)置之后無法自己關(guān)閉界面

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設(shè)置之后有了關(guān)閉選項(xiàng)

//窗口添加面板

JPanel jPanel = new JPanel();//創(chuàng)建組件

jPanel.setBackground(new Color(185, 213, 165));//設(shè)置創(chuàng)建組建的背景顏色

JButton jButton = new JButton("登錄");//在組件上添加按鈕,默認(rèn)添加水平居中

jButton.setLocation(10,10);//設(shè)置按鈕的距離邊距的大小

jButton.setBackground(Color.white);//設(shè)置按鈕顏色

jPanel.add(jButton);

this.add(jPanel);//功能設(shè)置完之后在添加到界面當(dāng)中

this.setVisible(true);//啟動(dòng)窗口

}

public static void main(String[] args) {

new MyJFrame();

}

}

?執(zhí)行結(jié)果為:

?3.2邊界布局

在創(chuàng)建面板的時(shí)候,就要選擇創(chuàng)鍵的面板:

JPanel jPanel = new JPanel(new BorderLayout());

此代碼執(zhí)行的結(jié)果就是創(chuàng)建了一個(gè)邊界布局的面板。

邊界布局的格式為:

在邊界布局中添加組件的代碼為:

public class Demo3Border extends JFrame {

public Demo3Border() throws HeadlessException {

this.setTitle("窗口標(biāo)題");//設(shè)置窗口標(biāo)題

this.setSize(700,500);//設(shè)置窗口大小

this.setLocation(200,200);//設(shè)置界面邊距大小

//this.setLocation(300,400);//設(shè)置窗口在界面的顯示位置

this.setLocationRelativeTo(null);//設(shè)置窗戶口顯示位置水平居中

this.setResizable(false);//設(shè)置之后禁止設(shè)置窗口大小

//邊界布局

JPanel jPanel = new JPanel(new BorderLayout());

JButton jb1 = new JButton("登錄1");//指定組件在邊界布局中的位置

jb1.setSize(100,100);

JButton jb2 = new JButton("登錄2");

JButton jb3 = new JButton("登錄3");

jPanel.add(jb1,BorderLayout.EAST);

jPanel.add(jb2,BorderLayout.NORTH);

jPanel.add(jb3,BorderLayout.SOUTH);

this.add(jPanel);

this.setVisible(true);

}

public static void main(String[] args) {

new Demo3Border();

}

}

執(zhí)行的結(jié)果如下:

?若是在添加時(shí)不設(shè)置顯示位置,就會(huì)默認(rèn)將組件放在中間位置。

3.3網(wǎng)格布局

創(chuàng)建網(wǎng)格布局的代碼為;

JPanel jp = new JPanel(new GridLayout(2,2));

//注意:在創(chuàng)建網(wǎng)格布局的時(shí)候,要給定網(wǎng)格的布局(幾行幾列)

public class Demo4Grid extends JFrame {

public Demo4Grid() throws HeadlessException {

this.setTitle("窗口標(biāo)題");//設(shè)置窗口標(biāo)題

this.setSize(700,500);//設(shè)置窗口大小

this.setLocation(200,200);//設(shè)置界面邊距大小

//this.setLocation(300,400);//設(shè)置窗口在界面的顯示位置

this.setLocationRelativeTo(null);//設(shè)置窗戶口顯示位置水平居中

this.setResizable(false);//設(shè)置之后禁止設(shè)置窗口大小

//網(wǎng)格布局

JPanel jp = new JPanel(new GridLayout(2,2));

JButton jb1 = new JButton("登錄1");

JButton jb2 = new JButton("登錄2");

JButton jb3 = new JButton("登錄3");

JButton jb4 = new JButton("登錄4");

jp.add(jb1);

jp.add(jb2);

jp.add(jb3);

jp.add(jb4);

this.add(jp);

this.setVisible(true);

}

public static void main(String[] args) {

new Demo4Grid();

}

}

執(zhí)行的結(jié)果為:

四.文本框

?標(biāo)簽(JLabel) 標(biāo)簽是容納文本和圖標(biāo)的控件,通常用來在界面中標(biāo)識(shí)別的控件。

4.1JLabe

構(gòu)造函數(shù): JLabel() 創(chuàng)建一個(gè)空的標(biāo)簽

? ? ? ? ? ? ? ? ? ?JLabel(String text) 創(chuàng)建一個(gè)帶文本的標(biāo)簽

? ? ? ? ? ? ? ? ? ?JLabel(Icon image) 創(chuàng)建一個(gè)帶圖像的標(biāo)簽

方法: void setText(String text) 設(shè)置標(biāo)簽上的文本?

? ? ? ? ? ? String getText() 獲得標(biāo)簽上的文本

? ? ? ? ? ? setFont(new Font(“宋體”,Font.BOLD, 18)); 設(shè)置文本框字體

4.2JTextField

單行文本(JTextField)

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

JTextField() JTextField(String text )

JTextField(int columns)

JTextField(String text, int columns) 方法:

void setText(String text) 設(shè)置文本框中的文本

String getText() 獲得文本框中的文本

void setEditable(boolean b) 設(shè)置文本框是否可以編輯

setColumns(20); 設(shè)置列數(shù)

在代碼中的具體實(shí)現(xiàn):

public class Demo6Label extends JFrame {

public Demo6Label() throws HeadlessException {

this.setTitle("窗口標(biāo)題");

this.setSize(500, 500);//大小

//this.setLocation(300, 500);//位置坐標(biāo)

this.setLocationRelativeTo(null);//相對(duì)位置 水平垂直居中

this.setResizable(false);//禁止設(shè)置窗口大小

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//關(guān)閉窗口選項(xiàng)

//默認(rèn)流式布局

JPanel jp = new JPanel();

JLabel jl = new JLabel("賬號(hào)");

jl.setForeground(Color.BLUE);//設(shè)置字體顏色

jl.setFont(new Font("楷體",Font.BOLD,20));

JTextField jt =new JTextField(20);//創(chuàng)建文本框

JButton jb = new JButton("登錄");

jp.add(jl);

jp.add(jt);

jp.add(jb);

this.add(jp);

this.setVisible(true);

}

public static void main(String[] args) {

new Demo6Label();

}

}

代碼實(shí)現(xiàn)的結(jié)果為:

4.4 多行文本框(JTextArea)

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

JTextArea() 創(chuàng)建一個(gè)空的文本域

JTextArea(String text) 用指定文本初始化文本域

JTextArea(int rows, int columns) 創(chuàng)建一個(gè)指定行數(shù)和列數(shù)的空文本域

JTextArea(String text,int rows, int columns) 創(chuàng)建一個(gè)帶文本,并指行數(shù)和列數(shù)的

方法:

void setText(String text) 設(shè)置文本域中的文本

String getText() 獲得文本域中的文本

void setFont(Font font) 設(shè)置文本域中文本的字體

void setLineWrap(boolean wrap) //是否自動(dòng)換行,默認(rèn)false 如果需要文本區(qū)自動(dòng)出現(xiàn)滾動(dòng)條,可將文本區(qū)對(duì)象放入

滾動(dòng)窗格(JScrollPane)中: JScrollPane scrollPane = new JScrollPane(txtArea);

add(scrollPane )

這些常用的方法在代碼中的具體實(shí)現(xiàn):

public class Demo7JTextArea extends JFrame {

public Demo7JTextArea() throws HeadlessException {

this.setTitle("文本框");//設(shè)置文本框標(biāo)題

this.setSize(900,700);//是指GUI界面的大小

this.setLocationRelativeTo(null);//設(shè)置文本框水平居中

this.setResizable(false);//設(shè)置能否修改窗口大小

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//關(guān)閉窗口選項(xiàng)

JPanel jp = new JPanel();

//多行輸入文本框

JTextArea jTextArea = new JTextArea(10,20);

jTextArea.setLineWrap(true);//自動(dòng)換行

jTextArea.setWrapStyleWord(true);//換行時(shí)必須是完整的字符換行

JScrollPane jScrollPane = new JScrollPane(jTextArea);//給此文本框加滾動(dòng)條

jp.add(jScrollPane);

this.add(jp);

this.setVisible(true);

}

public static void main(String[] args) {

new Demo7JTextArea();

}

}

實(shí)現(xiàn)之后的結(jié)果:

?4.5按鈕

按鈕(JButton)

構(gòu)造方法:

JButton(String text) 創(chuàng)建一個(gè)帶文本的標(biāo)簽

JButton(Icon image) 創(chuàng)建一個(gè)帶圖像的標(biāo)簽

方法:

void setBackground(Color bg) 設(shè)置按鈕的背景色

void setEnabled(boolean b) 設(shè)置啟用(或禁用)按鈕,由參數(shù)b決定

void setToolTipText(String text) 設(shè)置按鈕的懸停提示信息

五.菜單

菜單欄組件:

構(gòu)造方法:

JMenuBar();

方法:

add(menu); 向菜單欄添加菜單

菜單組件:

構(gòu)造方法:

JMenu(“菜單名稱");

方法:add(menuItem); 向菜單添加菜單選項(xiàng)

菜單項(xiàng)組件:

構(gòu)造方法:

JMenuItem(“菜單項(xiàng)名稱");

將菜單欄添加到窗口 setJMenuBar(menuBar);

菜單加到面板的具體操作:

public class Demo8JMenuBar extends JFrame {

public Demo8JMenuBar() throws HeadlessException {

this.setTitle("文本框");//設(shè)置文本框標(biāo)題

this.setSize(300,200);//是指GUI界面的大小

this.setLocationRelativeTo(null);//設(shè)置文本框水平居中

this.setResizable(false);//設(shè)置能否修改窗口大小

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//關(guān)閉窗口選項(xiàng)

//設(shè)置窗口菜單

//菜單分為三部分 菜單欄,菜單,菜單項(xiàng)

JPanel jPanel = new JPanel();

JMenuBar jMenuBar = new JMenuBar();//創(chuàng)建菜單欄

JMenu jMenu1 = new JMenu("選擇");//創(chuàng)建菜單

JMenuItem jMenuItem1 = new JMenuItem("保存");//創(chuàng)建菜單項(xiàng)

JMenuItem jMenuItem2 = new JMenuItem("刪除");

jMenu1.add(jMenuItem1);

jMenu1.add(jMenuItem2);

JMenu jMenu2 = new JMenu("編輯");

JMenuItem ji3 = new JMenuItem("剪切");

JMenuItem ji4 = new JMenuItem("復(fù)制");

jMenu2.add(ji3);

jMenu2.add(ji4);

JMenu jMenu3 = new JMenu("幫助");

JMenuItem ji5 = new JMenuItem("關(guān)于");

jMenu3.add(ji5);

jMenuBar.add(jMenu1);

jMenuBar.add(jMenu2);

jMenuBar.add(jMenu3);

this.setJMenuBar(jMenuBar);

this.add(jPanel);

this.setVisible(true);

}

public static void main(String[] args) {

new Demo8JMenuBar();

}

}

?代碼實(shí)現(xiàn)的結(jié)果:

六.事件處理

一個(gè)源(事件源)產(chǎn)生一個(gè)事件(事件對(duì)象)并把它送到監(jiān)聽器那里, 監(jiān)聽器只是簡單地等待,直到它收到一個(gè)事件,一旦事件被接受,監(jiān)聽 器將處理這些事件。

一個(gè)事件源必須注冊(cè)監(jiān)聽器以便監(jiān)聽器可以接受關(guān)于一個(gè)特定事件的通知。

添加事件監(jiān)聽器(此處即為匿名類) 按鈕對(duì)象.

addActionListener(new ActionListener() {

// 事件處理

@Override public void actionPerformed(ActionEvent e) {

執(zhí)行操作 }

});

在代碼中的具體實(shí)現(xiàn):

package com.ffyc.javaGUI.guitest.test3;

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

public class GridDemo3 extends JFrame {

public GridDemo3() throws HeadlessException {

this.setTitle("登錄界面");

this.setSize(300,200);//設(shè)置大小

this.setLocationRelativeTo(null);//設(shè)置窗口水平居中

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設(shè)置窗口關(guān)閉選項(xiàng)

this.setResizable(false);//禁止修改窗口大小

//添加菜單

JMenuBar jMenuBar = new JMenuBar();

JMenu jMenu1 = new JMenu("文件");

JMenuItem jMenuItem1 = new JMenuItem("保存");

JMenuItem jMenuItem2 = new JMenuItem("新建");

jMenu1.add(jMenuItem1);

jMenu1.add(jMenuItem2);

JMenu jMenu2 = new JMenu("幫助");

jMenuBar.add(jMenu1);

jMenuBar.add(jMenu2);

//網(wǎng)格布局

JPanel jPanel = new JPanel(new GridLayout(3,1));

JPanel jPanel1 = new JPanel();

JLabel jLabel = new JLabel("賬戶");

//jLabel.setForeground(new Color(0x4DBB6EEA, true));

jLabel.setFont(new Font("",Font.BOLD,15));

JTextField jTextField = new JTextField(15);

jPanel1.add(jLabel);

jPanel1.add(jTextField);

JPanel jPanel2 = new JPanel();

JLabel jLabel1 = new JLabel("密碼");

jLabel1.setFont(new Font("",Font.BOLD,15));

JPasswordField jTextField1 = new JPasswordField(15);

jPanel2.add(jLabel1);

jPanel2.add(jTextField1);

JPanel jPanel3 = new JPanel();

JButton jButton = new JButton("登錄");

jPanel3.add(jButton);

jPanel.add(jPanel1);

jPanel.add(jPanel2);

jPanel.add(jPanel3);

this.add(jPanel);

this.setJMenuBar(jMenuBar);//將菜單添加到窗口

this.setVisible(true);

jButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

JOptionPane.showConfirmDialog(null,"是否登錄賬號(hào)");

if(jTextField.getText().length()<=0){

System.out.println("賬號(hào)不能為空");

}else{

if(jTextField.getText().equals("123456")||jTextField1.getText().equals("123456")){

JOptionPane.showMessageDialog(null,"登錄成功","操作提示",JOptionPane.INFORMATION_MESSAGE);

}else {

JOptionPane.showMessageDialog(null,"賬號(hào)或密碼錯(cuò)誤");

}

}

}

});

jMenu1.addMouseListener(new MouseAdapter() {//點(diǎn)擊操作

@Override

public void mouseClicked(MouseEvent e) {

JOptionPane.showMessageDialog(null,"點(diǎn)擊");

}

});

}

public static void main(String[] args) {

new GridDemo3();

}

}

結(jié)果:

JOptionPane對(duì)話框

showMessageDialog():消息對(duì)話框

主要有五種消息類型,類型不同,圖標(biāo)不同:

ERROR_MESSAGE 錯(cuò)誤消息提示

INFORMATION_MESSAGE 信息提示

WARNING_MESSAGE 警告提示

QUESTION_MESSAGE 問題提示

PLAIN_MESSAGE 簡潔提示

showConfirmDialog():確認(rèn)對(duì)話框 主要有四種消息類型,類型不同,

圖標(biāo)不同: DEFAULT_OPTION 默認(rèn)選項(xiàng)

YES_NO_OPTION 是/否選項(xiàng)

YES_NO_CANCEL_OPTION 是/否/取消選項(xiàng)

?OK_CANCEL_OPTION 確定/取消

?

柚子快報(bào)激活碼778899分享:開發(fā)語言 JAVA中的GUI

http://yzkb.51969.com/

參考鏈接

評(píng)論可見,查看隱藏內(nèi)容

本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場。

轉(zhuǎn)載請(qǐng)注明,如有侵權(quán),聯(lián)系刪除。

本文鏈接:http://gantiao.com.cn/post/17817319.html

發(fā)布評(píng)論

您暫未設(shè)置收款碼

請(qǐng)?jiān)谥黝}配置——文章設(shè)置里上傳

掃描二維碼手機(jī)訪問

文章目錄