java显示不了窗体,有没有人能帮忙看一下,为什么我的窗体显示不出来

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

afa7d0e4501347d374300a6333b611c7.png

package gui;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

import java.sql.ResultSet;

import java.sql.SQLException;

public class Main {

private JFrame frame;

private JTextField textField;

private JTextField textField_1;

private JTextField textField_2;

//-----------单选按钮

JRadioButton radioButton_1;

JRadioButton radioButton;

/**

* Launch the application.

*/

public static void main(String[] args)

{

try {

Main window = new Main();

System.out.println("wu");

window.frame.setVisible(true);

} catch (Exception e)

{

e.printStackTrace();

}

}

/**

* Create the application.

*/

public Main() {

initialize();

}

/**

* Initialize the contents of the frame.

*/

private void initialize() {

frame = new JFrame();

frame.setBounds(100, 100, 450,500);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

/**

* 背景图片模块

*/

JPanel panel_image = new JPanel();//背景图片面板

panel_image.setBackground(Color.LIGHT_GRAY);

frame.getContentPane().add(panel_image, BorderLayout.NORTH);

JLabel label = new JLabel("");

label.setIcon(new ImageIcon("/Users/yueboyang/Documents/gongjiaoguanlixitong4.png"));

panel_image.add(label);

/**

* 功能模块

*/

JPanel panel_function = new JPanel();

frame.getContentPane().add(panel_function, BorderLayout.CENTER);

panel_function.setLayout(new GridLayout(6,2));

/**

* 选择查询方式

*/

JPanel panel_select = new JPanel();

panel_select.setBackground(Color.BLACK);

panel_function.add(panel_select);

//按车次查询单选按钮

radioButton = new JRadioButton("按车次查询");

radioButton.setFont(new Font("Lucida Grande", Font.PLAIN, 16));

radioButton.setForeground(Color.WHITE);

radioButton.addActionListener(new selectListener());

panel_select.add(radioButton);

//按站点查询单选按钮

radioButton_1 = new JRadioButton("按站点查询");

radioButton_1.setFont(new Font("Lucida Grande", Font.PLAIN, 16));

radioButton_1.setForeground(Color.WHITE);

radioButton_1.addActionListener(new selectListener());

panel_select.add(radioButton_1);

//按选按钮组

ButtonGroup buttongroup = new ButtonGroup();

buttongroup.add(radioButton); buttongroup.add(radioButton_1);

/**

* 按站点查询模块图片

*/

JPanel searchByst = new JPanel();

searchByst.setBackground(Color.BLACK);

panel_function.add(searchByst);

JLabel label_1 = new JLabel("");

label_1.setIcon(new ImageIcon("/Users/yueboyang/Documents/anzhandianchaxun5.png"));

searchByst.add(label_1);

/**

* 按站点查询功能模块

*/

JPanel RsearchByst = new JPanel();

RsearchByst.setBackground(Color.BLACK);

panel_function.add(RsearchByst);

JLabel label_2 = new JLabel("出发站");

label_2.setFont(new Font("Lucida Grande", Font.PLAIN, 19));

label_2.setForeground(Color.WHITE);

RsearchByst.add(label_2);

textField = new JTextField();

RsearchByst.add(textField);

textField.setColumns(10);

JLabel label_3 = new JLabel("终点站");

label_3.setFont(new Font("Lucida Grande", Font.PLAIN, 19));

label_3.setForeground(Color.WHITE);

RsearchByst.add(label_3);

textField_1 = new JTextField();

RsearchByst.add(textField_1);

textField_1.setColumns(10);

/**

* 按车次查询模块图片

*/

JPanel searchByNum = new JPanel();

searchByNum.setBackground(Color.BLACK);

panel_function.add(searchByNum);

JLabel label_4 = new JLabel("");

label_4.setIcon(new ImageIcon("/Users/yueboyang/Documents/anchecichaxun3.png"));

searchByNum.add(label_4);

/**

* 按车次查询模块功能

*/

JPanel RsearchByNum = new JPanel();

RsearchByNum.setBackground(Color.BLACK);

panel_function.add(RsearchByNum);

JLabel label_5 = new JLabel("查询车次");

label_5.setFont(new Font("Lucida Grande", Font.PLAIN, 19));

label_5.setForeground(Color.WHITE);

RsearchByNum.add(label_5);

textField_2 = new JTextField();

RsearchByNum.add(textField_2);

textField_2.setColumns(10);

JPanel panel_button = new JPanel();//确认模块

panel_button.setBackground(Color.LIGHT_GRAY);

panel_function.add(panel_button);

JButton button = new JButton("确定");

/**---------------确定按钮监听器----------------*/

button.addActionListener(new ActionListener() {

String str; //车次

String str1; String str2;//出发站、终点站

int is_Select; //0是按站点查询 1是按车次查询

public void actionPerformed(ActionEvent e) {

//跳转,读取数据库数据 两个分支

if( radioButton_1.isSelected()) //按站点查询功能

{

str1 = textField.getText();

str2 = textField_1.getText();

is_Select = 0;

}

else if( radioButton.isSelected() )//按车次查询功能

{

str = textField_2.getText();

is_Select = 1;

}

//跳转

//根据is_Select获得相应数据

//显示

}

});

button.setFont(new Font("Lucida Grande", Font.PLAIN, 15));

panel_button.add(button);

JButton button_1 = new JButton("不是很确定");

/**-------------不是很确定按钮监听器-------------*/

button_1.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

textField.setText("");

textField_1.setText("");

textField_2.setText("");

}

});

button_1.setFont(new Font("Lucida Grande", Font.PLAIN, 15));

panel_button.add(button_1);

}

class selectListener implements ActionListener{ //选择查询方式监听器

/**

* 选择按车次查询,按站点查询文本框关闭输入

*/

@Override

public void actionPerformed(ActionEvent e)

{

if(radioButton.isSelected())

{

textField_2.setEditable(false);

textField.setEditable(true);

textField_1.setEnabled(true);

}

else if(radioButton_1.isSelected())

{

textField_2.setEditable(true);

textField.setEditable(false);

textField_1.setEnabled(false);

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值