java 程序运行结果_关于java程序运行结果的問題,请指教哦

你的frame没布局,加一个就可以了 代码如下。

import java.awt.event.*;

import java.awt.*;

import javax.swing.*;

public class Example2

{

public static void main(String args[]) {

WindowEventAction win = new WindowEventAction();

win.setBounds(100, 100, 300, 300);

win.setTitle("图书馆查询系统");

}

}

class WindowEventAction extends JFrame {

GridLayout grid;

JPanel panel;

JButton an1, an2, an3, an4, an5;

JTextField text;

JTextArea area;

JComboBox box;

public WindowEventAction() {

Menu();

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void Menu() {

setLayout(new FlowLayout());

grid = new GridLayout(2, 2);

panel = new JPanel();

panel.setLayout(grid);

an1 = new JButton("查询");

an2 = new JButton("录入");

an3 = new JButton("修改");

an4 = new JButton("删除");

an5 = new JButton("退出");

area = new JTextArea(10, 30);

box = new JComboBox();

text = new JTextField(10);

box.addItem("请选择查找方式:");

box.addItem("作者");

box.addItem("价格");

JLabel label[][] = new JLabel[2][2];

for (int i = 0; i < 2; i++) {

for (int j = 0; j < 2; j++) {

if (i == 0) {

if (j == 0)

label[i][j] = new JLabel("1");

else

label[i][j] = new JLabel("2");

} else {

if (j == 0)

label[i][j] = new JLabel("3");

else

label[i][j] = new JLabel("4");

}

panel.add(label[i][j]);

}

}

for (int i = 0; i < 2; i++) {

for (int j = 0; j < 2; j++) {

switch (Integer.parseInt(label[i][j].getText())) {

case 1:

add(an1);

add(an2);

add(an3);

add(an4);

break;

case 2:

add(box);

add(text);

break;

case 3:

case 4:

add(new JScrollPane(area));

}

}

}

}

}

取消

评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值