国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

Java swing超詳細(xì)解析:點(diǎn)擊不同的按鈕切換對(duì)應(yīng)的面板界面,Jpanel【詩(shī)書(shū)畫唱】

2020-05-28 13:11 作者:詩(shī)書(shū)畫唱  | 我要投稿


package swing;


public class mains {


public static void main(String[] args) {


new swingJpanel();

}


}


package swing;

import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;


import javax.swing.*;

public class swingJpanel extends JFrame{

public static JPanel jpRed,jpPink,jpBlueRightBottom1,jpGreenRightBottom2;

public static JButton btn1,btn2;

public swingJpanel(){

//swing中必要的代碼內(nèi)容:布局方式、大小、位置、釋放資源、顯示

this.setLayout(null);

this.setSize(700,700);

// 下面的代碼的意思就是把位置設(shè)置為居中

this.setLocationRelativeTo(null);

jpRed=new JPanel();

jpPink=new JPanel();

jpBlueRightBottom1=new JPanel();

jpGreenRightBottom2=new JPanel();


jpRed.setLayout(null);//將jp1的布局方式也設(shè)置為空布局

btn1=new JButton("點(diǎn)贊界面");

btn2=new JButton("三連關(guān)注界面");

btn1.setBounds(100,30,120,90);

btn2.setBounds(250,30,120,90);

btn1.addActionListener(new swingJpanel_shijian(this));

btn2.addActionListener(new swingJpanel_shijian(this));

jpRed.add(btn1);jpRed.add(btn2);

jpRed.setBorder(BorderFactory.createLineBorder(Color.red));

jpPink.setBorder(BorderFactory.createLineBorder(Color.pink));

jpBlueRightBottom1.setBorder(BorderFactory.createLineBorder(Color.blue));

jpGreenRightBottom2.setBorder(BorderFactory.createLineBorder(Color.green));

jpRed.setBounds(10,10,600,150);

jpPink.setBounds(10,170,200,450);

jpBlueRightBottom1.setBounds(220, 170, 380, 450);

jpGreenRightBottom2.setBounds(220, 170, 380, 450);

//jp3.setBounds(220, 170, 380, 450);

this.add(jpRed);this.add(jpPink);

this.add(jpGreenRightBottom2);

this.add(jpBlueRightBottom1);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setVisible(true);

}

}

//使用第二種方式(就是傳窗口)得到頁(yè)面的控件

class swingJpanel_shijian implements ActionListener{

public static swingJpanel ss;//現(xiàn)在的ss就是擁有控件的窗體了

public swingJpanel_shijian(swingJpanel s){

ss=s;

}

@Override

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

//判斷用戶點(diǎn)擊的是那個(gè)按鈕

String neirong=arg0.getActionCommand();//接收點(diǎn)擊按鈕的內(nèi)容

if(neirong.equals("點(diǎn)贊界面")){

//JOptionPane.showMessageDialog(null,"點(diǎn)擊了第一個(gè)按鈕");

ss.jpBlueRightBottom1.setVisible(true);

ss.jpGreenRightBottom2.setVisible(false);

}else if(neirong.equals("三連關(guān)注界面")){

// JOptionPane.showMessageDialog(null,"點(diǎn)擊了第二個(gè)按鈕");

ss.jpBlueRightBottom1.setVisible(false);

ss.jpGreenRightBottom2.setVisible(true);

}

}


}


Java swing超詳細(xì)解析:點(diǎn)擊不同的按鈕切換對(duì)應(yīng)的面板界面,Jpanel【詩(shī)書(shū)畫唱】的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
英超| 泾阳县| 奉化市| 常宁市| 赤水市| 大洼县| 临海市| 滨海县| 岳池县| 秦皇岛市| 图木舒克市| 广灵县| 乌海市| 临猗县| 安达市| 六盘水市| 天等县| 白城市| 盐津县| 梁山县| 武川县| 岱山县| 龙南县| 安康市| 瑞安市| 镇江市| 潮州市| 博兴县| 临湘市| 梅州市| 府谷县| 喜德县| 微博| 叶城县| 雅江县| 江门市| 祁门县| 集安市| 项城市| 嵊泗县| 连州市|