Java 我如何制作一个GUI,看起来像一个简单的股票市场应用程序的附加图片?

Java 我如何制作一个GUI,看起来像一个简单的股票市场应用程序的附加图片?,java,swing,layout,Java,Swing,Layout,使用这些布局;FlowLayout、BoxLayout、GridLayout、BorderLayout和GridBagLayout我试图让我的GUI看起来像下面这样。我尝试了流、网格和边框,但无法使其看起来相同 使用(它在网站上看起来真的很复古,现在真的很好)。我建议使用GridBagLayout。我知道,我知道,这是一段糟糕的代码,但是有了Netbean的表单编辑器,当你掌握了窍门时,它会变得超级简单和强大。以下是如何在面板中设置组件: topPanel: -leftPanel: --outp

使用这些布局;FlowLayout、BoxLayout、GridLayout、BorderLayout和GridBagLayout我试图让我的GUI看起来像下面这样。我尝试了流、网格和边框,但无法使其看起来相同

使用(它在网站上看起来真的很复古,现在真的很好)。我建议使用GridBagLayout。我知道,我知道,这是一段糟糕的代码,但是有了Netbean的表单编辑器,当你掌握了窍门时,它会变得超级简单和强大。以下是如何在面板中设置组件:

topPanel:
-leftPanel:
--outputLable
-rightPanel:
--companyLable
--priceLabel
--changeLabel
--dividentLabel
--marketCapLabel
--stockExchangeLabel
bottomPanel:
-panel1:
--inputLabel
-panel2:
--0Label
--1Label
--etc...
-panel3:
--qLabel
--wLabel
--etc...
-panel4:
--etc...
-panel5:
--etc...

并使按钮的标签具有图像图标,这些图标是您根据所给的图像指定的。(如果你想要一个调整图像大小的好方法,你可以在我的网站上看到我的方法。我并不声称自己在这方面是最好的,但是GUI是我可以很好地处理的东西(如果你给我表单编辑器,哈哈),这个方法可能不是最好的,但它对我来说非常有用:)。祝你好运

我试着模仿你想要的,似乎我更接近你想要的,请看一下代码和图像:

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

public class MakingLayout extends JFrame
{
    public MakingLayout()
    {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        JPanel contentPane = new JPanel();
        contentPane.setLayout(new BorderLayout());

        JPanel leftPanel = new JPanel();
        JLabel leftLabel = new JLabel("Output : ", JLabel.CENTER);

        leftPanel.add(leftLabel);

        JPanel centerPanel = new JPanel();
        centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));

        JLabel centerFirstLabel = new JLabel("Google Inc.", JLabel.LEFT);
        JLabel centerSecondLabel = new JLabel("Price : 618.405", JLabel.LEFT);
        JLabel centerThirdLabel = new JLabel("<html>Change : <font color = red>-4.06 (-0.65%)</font> </html>", JLabel.LEFT);
        JLabel centerFourthLabel = new JLabel("Divident : 0.00", JLabel.LEFT);
        JLabel centerFifthLabel = new JLabel("Market Cap : 200.38", JLabel.LEFT);
        JLabel centerSixthLabel = new JLabel("Stock Exchange : NasdaqNM", JLabel.LEFT);

        centerPanel.add(centerFirstLabel);
        centerPanel.add(centerSecondLabel);
        centerPanel.add(centerThirdLabel);
        centerPanel.add(centerFourthLabel);
        centerPanel.add(centerFifthLabel);
        centerPanel.add(centerSixthLabel);

        JPanel bottomPanel = new JPanel();
        bottomPanel.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.weightx = 1.0;
        gbc.weighty = 0.1;
        gbc.anchor = GridBagConstraints.PAGE_START;
        JLabel bottomLabel = new JLabel(" Input : ", JLabel.LEFT);

        JPanel digitPanel = new JPanel();
        JButton[] button = new JButton[10];
        for (int i = 0; i < 10; i++)
        {
            button[i] = new JButton("" + i);
            digitPanel.add(button[i]);
        }

        JPanel topLinePanel = new JPanel();
        JButton[] buttonTop = new JButton[11];
        buttonTop[0] = new JButton("Q");
        buttonTop[1] = new JButton("W");
        buttonTop[2] = new JButton("E");
        buttonTop[3] = new JButton("R");
        buttonTop[4] = new JButton("T");
        buttonTop[5] = new JButton("Y");
        buttonTop[6] = new JButton("U");
        buttonTop[7] = new JButton("I");
        buttonTop[8] = new JButton("O");
        buttonTop[9] = new JButton("P");
        buttonTop[10] = new JButton("DEL");
        for (int i = 0; i < 11; i++)
        {
            topLinePanel.add(buttonTop[i]);
        }

        JPanel middleLinePanel = new JPanel();
        JButton[] buttonMiddle = new JButton[10];
        buttonMiddle[0] = new JButton("A");
        buttonMiddle[1] = new JButton("S");
        buttonMiddle[2] = new JButton("D");
        buttonMiddle[3] = new JButton("F");
        buttonMiddle[4] = new JButton("G");
        buttonMiddle[5] = new JButton("H");
        buttonMiddle[6] = new JButton("J");
        buttonMiddle[7] = new JButton("K");
        buttonMiddle[8] = new JButton("L");
        buttonMiddle[9] = new JButton("RET");
        for (int i = 0; i < 10; i++)
        {
            middleLinePanel.add(buttonMiddle[i]);
        }

        JPanel bottomLinePanel = new JPanel();
        JButton[] buttonBottom = new JButton[8];
        buttonBottom[0] = new JButton("Z");
        buttonBottom[1] = new JButton("X");
        buttonBottom[2] = new JButton("C");
        buttonBottom[3] = new JButton("V");
        buttonBottom[4] = new JButton("B");
        buttonBottom[5] = new JButton("N");
        buttonBottom[6] = new JButton("M");
        buttonBottom[7] = new JButton(".");
        for (int i = 0; i < 8; i++)
        {
            bottomLinePanel.add(buttonBottom[i]);
        }

        bottomPanel.add(bottomLabel, gbc);
        gbc.gridy = 1;
        bottomPanel.add(digitPanel, gbc);
        gbc.gridy = 2;
        bottomPanel.add(topLinePanel, gbc);
        gbc.gridy = 3;
        bottomPanel.add(middleLinePanel, gbc);
        gbc.gridy = 4;
        bottomPanel.add(bottomLinePanel, gbc);

        contentPane.add(leftPanel, BorderLayout.WEST);
        contentPane.add(centerPanel, BorderLayout.CENTER);
        contentPane.add(bottomPanel, BorderLayout.PAGE_END);

        setContentPane(contentPane);
        pack();
        setVisible(true);       
    }

    public static void main(String... args)
    {
        SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                new MakingLayout();
            }
        });
    }
}
import java.awt.*;
导入javax.swing.*;
公共类生成布局扩展JFrame
{
公共制作布局(图)
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(空);
JPanel contentPane=新的JPanel();
setLayout(新的BorderLayout());
JPanel leftPanel=新的JPanel();
JLabel leftLabel=新的JLabel(“输出:”,JLabel.CENTER);
leftPanel.add(leftLabel);
JPanel centerPanel=新的JPanel();
centerPanel.setLayout(新的BoxLayout(centerPanel,BoxLayout.Y_轴));
JLabel centerFirstLabel=新的JLabel(“谷歌公司”,JLabel.LEFT);
JLabel centerSecondLabel=新的JLabel(“价格:618.405”,JLabel.左);
JLabel centerThirdLabel=新JLabel(“变更:-4.06(-0.65%)”,JLabel.左);
JLabel centerFourthLabel=新JLabel(“Divident:0.00”,JLabel.左);
JLabel centerFifthLabel=新JLabel(“市值:200.38”,JLabel.左);
JLabel centerSixthLabel=新的JLabel(“证券交易所:NasdaqNM”,JLabel.LEFT);
centerPanel.add(centerFirstLabel);
centerPanel.add(centerSecondLabel);
centerPanel.add(centerThirdLabel);
centerPanel.add(centerFourthLabel);
centerPanel.add(centerFifthLabel);
centerPanel.add(centerSixthLabel);
JPanel bottomPanel=新的JPanel();
setLayout(新的GridBagLayout());
GridBagConstraints gbc=新的GridBagConstraints();
gbc.gridx=1;
gbc.gridy=0;
gbc.fill=GridBagConstraints.HORIZONTAL;
gbc.weightx=1.0;
gbc.weighty=0.1;
gbc.anchor=gridbagsconstraints.PAGE_START;
JLabel bottomLabel=新的JLabel(“输入:”,JLabel.LEFT);
JPanel digitPanel=新的JPanel();
JButton[]按钮=新JButton[10];
对于(int i=0;i<10;i++)
{
按钮[i]=新的JButton(“+i”);
添加(按钮[i]);
}
JPanel topLinePanel=新的JPanel();
JButton[]buttonTop=新JButton[11];
buttonTop[0]=新的JButton(“Q”);
按钮按钮[1]=新的按钮(“W”);
按钮按钮[2]=新的按钮(“E”);
按钮按钮[3]=新的按钮(“R”);
按钮按钮[4]=新的按钮(“T”);
按钮按钮[5]=新按钮(“Y”);
按钮按钮[6]=新的按钮(“U”);
按钮按钮[7]=新按钮(“I”);
按钮按钮[8]=新按钮(“O”);
按钮按钮[9]=新按钮(“P”);
按钮按钮[10]=新按钮(“DEL”);
对于(int i=0;i<11;i++)
{
topLinePanel.add(按钮顶部[i]);
}
JPanel middleLinePanel=新的JPanel();
JButton[]buttonMiddle=新JButton[10];
buttonMiddle[0]=新的JButton(“A”);
buttonMiddle[1]=新的JButton(“S”);
buttonMiddle[2]=新的JButton(“D”);
buttonMiddle[3]=新的JButton(“F”);
buttonMiddle[4]=新的JButton(“G”);
按钮中间[5]=新的按钮(“H”);
buttonMiddle[6]=新的JButton(“J”);
buttonMiddle[7]=新的JButton(“K”);
按钮中间[8]=新的按钮(“L”);
buttonMiddle[9]=新的JButton(“RET”);
对于(int i=0;i<10;i++)
{
添加(按钮中间[i]);
}
JPanel bottomLinePanel=新的JPanel();
JButton[]buttonBottom=新JButton[8];
buttonBottom[0]=新的JButton(“Z”);
buttonBottom[1]=新的JButton(“X”);
按钮底部[2]=新的按钮(“C”);
按钮底部[3]=新的按钮(“V”);
按钮底部[4]=新的按钮(“B”);
按钮底部[5]=新的按钮(“N”);
buttonBottom[6]=新的JButton(“M”);
buttonBottom[7]=新的JButton(“.”);
对于(int i=0;i<8;i++)
{
添加(按钮底部[i]);
}
底部面板。添加(底部标签,gbc);
gbc.gridy=1;
底部面板。添加(digitPanel,gbc);
gbc.gridy=2;
底部面板。添加(顶部面板,gbc);
gbc.gridy=3;
底部面板。添加(中线面板,gbc);
gbc.gridy=4;
bottomPanel.add(bottomLinePanel,gbc);
添加(leftPanel,BorderLayout.WEST);
contentPane.add(中心面板,BorderLayout.CENTER);
contentPane.add(底部面板,边框布局,页面结尾);
setContentPane(contentPane);
包装();
setVisible(真);
}
公共静态void main(字符串…参数)
{
SwingUtilities.invokeLater(新的Runnable()
{
公开募捐
{
新的制作布局();
}
});
}
}
以下是代码的结果:


在2000年代安装BMP被认为是一种不好的品味。你为什么要在屏幕上模拟键盘?如果你往下看,你在键盘上打字。我想你需要一个更实用的