gpt4 book ai didi

java - 手工编码的 GUI - Java

转载 作者:搜寻专家 更新时间:2023-11-01 02:14:18 25 4
gpt4 key购买 nike

<分区>

我正在尝试使用 Swing 和 AWT 手动编写 Java GUI。我正在使用各种布局来尝试实现或类似于下面发布的 GUI(这是一个用铅笔制作的模拟布局):

Mock Layout - (Made with Pencil)

到目前为止我得到的是这个,但似乎无法让它变得更“礼貌”、吸引人和尽可能对用户友好。

Java GUI try

这是我到目前为止完成的代码:

import java.awt.*; 
import javax.swing.*;
import javax.swing.JTable;


public class GUI extends JFrame {

public void buildGui() {

JFrame frame = new JFrame("Hotel TV Scheduler");

JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout(0,0));

JPanel chPanel = new JPanel();
chPanel.setLayout(new GridLayout(3,2));

JPanel listPanel = new JPanel();
listPanel.setLayout(new GridLayout(3,2));

JPanel infoPanel = new JPanel();
infoPanel.setLayout(new GridLayout(0,2));


JPanel addPanel = new JPanel();
addPanel.setLayout(new GridLayout(0,3));


mainPanel.add(chPanel, BorderLayout.LINE_START);
mainPanel.add(listPanel, BorderLayout.CENTER);
mainPanel.add(infoPanel, BorderLayout.LINE_END);


JTable chOneTable = new JTable();
JTable chTwoTable = new JTable();
JTable listTable = new JTable();

JLabel ch1Label = new JLabel("Channel 1");
JLabel ch2Label = new JLabel("Channel 2");
JLabel listLabel = new JLabel("List");

JButton rmvChOneButton = new JButton("Remove Channel");
JButton rmvChTwoButton = new JButton("Remove Channel");

chPanel.add(ch1Label);
chPanel.add(ch2Label);
chPanel.add(chOneTable);
chPanel.add(chTwoTable);
chPanel.add(rmvChOneButton);
chPanel.add(rmvChTwoButton);

listPanel.add(listLabel);
listPanel.add(listTable);



JLabel titleLabel = new JLabel("Title");
JLabel genreLabel = new JLabel("Genre");
JLabel durationLabel = new JLabel("Duration");
JLabel actorLabel = new JLabel("Actor");
JLabel directorLabel = new JLabel("Director");
JLabel rentableLabel = new JLabel("Rentable");
JLabel synLabel = new JLabel("Synopsis");

JTextField txtTitle = new JTextField();
JTextField txtGenre = new JTextField();
JTextField txtDuration = new JTextField();
JTextField txtActor = new JTextField();
JTextField txtDirector = new JTextField();
JTextField txtSynopsis = new JTextField();

JCheckBox rentCB = new JCheckBox();

JButton btnAddProg = new JButton("Add Program");

JList channelList = new JList();
JList timeList = new JList();

infoPanel.add(titleLabel);
infoPanel.add(txtTitle);
infoPanel.add(genreLabel);
infoPanel.add(txtGenre);
infoPanel.add(durationLabel);
infoPanel.add(txtDuration);
infoPanel.add(actorLabel);
infoPanel.add(txtActor);
infoPanel.add(directorLabel);
infoPanel.add(txtDirector);
infoPanel.add(rentableLabel);
infoPanel.add(rentCB);
infoPanel.add(synLabel);
infoPanel.add(txtSynopsis);
infoPanel.add(btnAddProg);
infoPanel.add(channelList);
infoPanel.add(timeList);


frame.add(mainPanel);
frame.setVisible(true);


}


}

它不必与上面显示的模拟布局完全相同,但尽可能相似或至少对用户更友好。

除了 GridBagLayout 和 SwingLayout,我想使用任何东西。

关于如何改进代码并使其看起来更相似有什么想法吗?

感谢任何帮助。

布莱恩

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com