日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 多个 panel_java – 在JFrame中组织多个JPanel的好方法是...

發布時間:2025/3/12 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 多个 panel_java – 在JFrame中组织多个JPanel的好方法是... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我想要做的是在框架內組織五個單獨的JPanel.輸出應該是這樣的:頂部會有一個面板.頂部面板正下方的兩個面板垂直分割空間,然后另外兩個面板水平分割剩余空間.

我無法弄清楚如何組織如上所述的面板,我認為這是因為我只是不知道正確的語法.所以任何幫助或建議都非常感謝這里是我迄今為止的代碼.

import java.lang.String.*;

import java.lang.Exception.*;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class Display extends JFrame implements ActionListener{

// instance variables

private static final int FRAME_WIDTH = 400;

private static final int FRAME_HEIGHT = 350;

private static final int FRAME_X_ORIGIN = 150;

private static final int FRAME_Y_ORIGIN = 150;

private static final int BUTTON_WIDTH = 90;

private static final int BUTTON_HEIGHT = 30;

private JButton readFile;

private JButton exit;

private JButton stats;

private JButton blank;

private JCheckBox avgHomeworkScore;

private JCheckBox avgTestScore;

private JCheckBox sdHomeworkScore;

private JCheckBox sdTestScore;

private JRadioButton buttonOne;

private JRadioButton buttonTwo;

private JRadioButton buttonThree;

private JRadioButton buttonFour;

private JPanel header;

private JPanel statistics;

private JPanel courses;

private JPanel display;

private JPanel action;

public static void main(String[] args){

Display frame = new Display();

frame.setVisible(true);

}

public Display(){

Container contentPane;

//Set the frame properties

setSize (FRAME_WIDTH, FRAME_HEIGHT);

setResizable (false);

setTitle ("CSCE155A Course Offerings Viewer");

setLocation (FRAME_X_ORIGIN, FRAME_Y_ORIGIN);

contentPane = getContentPane();

contentPane.setLayout(new GridLayout());

contentPane.setBackground( Color.white );

//header

//Create and Place the Buttons on the frame

readFile = new JButton("Read File");

readFile.setBounds(4, 285, BUTTON_WIDTH, BUTTON_HEIGHT);

exit = new JButton("Exit");

exit.setBounds(100, 285, BUTTON_WIDTH, BUTTON_HEIGHT);

stats = new JButton("Stats");

stats.setBounds(195, 285, BUTTON_WIDTH, BUTTON_HEIGHT);

blank = new JButton("Clear");

blank.setBounds(290, 285, BUTTON_WIDTH, BUTTON_HEIGHT);

action = new JPanel(new FlowLayout());

action.setBackground(Color.blue);

action.add(readFile);

action.add(exit);

action.add(stats);

action.add(blank);

contentPane.add(action);

//Register this frame as an Action listener of the buttons

readFile.addActionListener(this);

exit.addActionListener(this);

stats.addActionListener(this);

blank.addActionListener(this);

//Create and Place the checkboxes on the frame

avgHomeworkScore = new JCheckBox();

avgHomeworkScore.setMnemonic(KeyEvent.VK_H);

contentPane.add(avgHomeworkScore);

avgHomeworkScore.setSelected(true);

avgTestScore = new JCheckBox();

avgTestScore.setMnemonic(KeyEvent.VK_T);

avgTestScore.setSelected(true);

sdHomeworkScore = new JCheckBox();

sdHomeworkScore.setMnemonic(KeyEvent.VK_S);

sdHomeworkScore.setSelected(true);

sdTestScore = new JCheckBox();

sdTestScore.setMnemonic(KeyEvent.VK_D);

sdTestScore.setSelected(true);

statistics = new JPanel(new GridLayout(0,1));

contentPane.add(statistics);

statistics.add(avgHomeworkScore);

statistics.add(avgTestScore);

statistics.add(sdHomeworkScore);

statistics.add(sdTestScore);

avgHomeworkScore.addActionListener(this);

avgTestScore.addActionListener(this);

sdHomeworkScore.addActionListener(this);

sdTestScore.addActionListener(this);

//create the radio buttons

buttonOne = new JRadioButton();

buttonOne.setMnemonic(KeyEvent.VK_1);

buttonOne.setSelected(true);

buttonTwo = new JRadioButton();

buttonTwo.setMnemonic(KeyEvent.VK_2);

buttonThree = new JRadioButton();

buttonThree.setMnemonic(KeyEvent.VK_3);

buttonFour = new JRadioButton();

buttonFour.setMnemonic(KeyEvent.VK_4);

ButtonGroup group = new ButtonGroup();

group.add(buttonOne);

group.add(buttonTwo);

group.add(buttonThree);

group.add(buttonFour);

buttonOne.addActionListener(this);

buttonTwo.addActionListener(this);

buttonThree.addActionListener(this);

buttonFour.addActionListener(this);

courses = new JPanel(new GridLayout(0,1));

courses.setBackground(Color.blue);

courses.add(buttonOne);

courses.add(buttonTwo);

courses.add(buttonThree);

courses.add(buttonFour);

contentPane.add(courses);

//Exit program when the viewer is closed

setDefaultCloseOperation(EXIT_ON_CLOSE);

}

總結

以上是生活随笔為你收集整理的java 多个 panel_java – 在JFrame中组织多个JPanel的好方法是...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。