java-如何制作一个看起来像简单的股市应用程序所附图片的GUI?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-如何制作一个看起来像简单的股市应用程序所附图片的GUI?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3860字,纯文字阅读大概需要6分钟。
内容图文
![java-如何制作一个看起来像简单的股市应用程序所附图片的GUI?](/upload/InfoBanner/zyjiaocheng/674/ab95482ac422458084dd3e245a7d090a.jpg)
使用这些布局;我试图使我的GUI如下所示的FlowLayout,BoxLayout,GridLayout,BorderLayout和GridBagLayout.我尝试了Flow,Grid和Border,但无法使其看起来相同.
解决方法:
我试图模仿您想要的东西,似乎我离您想要的东西有点近,请看一下代码和图像:
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();
}
});
}
}
这是代码的结果:
内容总结
以上是互联网集市为您收集整理的java-如何制作一个看起来像简单的股市应用程序所附图片的GUI?全部内容,希望文章能够帮你解决java-如何制作一个看起来像简单的股市应用程序所附图片的GUI?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。