java写gui简单查询功能_Java图形用户界面(GUI)工具包swing来写一个简单的留言板程序(不带数据库)...

这个Java程序演示了如何使用Swing库创建一个简单的GUI留言板应用。用户可以选择角色(管理员、博主、游客),输入留言并点击“发帖”按钮进行发布。此外,还提供了删除帖子、从头浏览和从尾浏览的功能,尽管删除功能在此实现中尚未完全完成。
摘要由CSDN通过智能技术生成

package demo2;

import java.awt.BorderLayout;

import javax.swing.JPanel;

import javax.swing.JFrame;

import java.awt.Rectangle;

import javax.swing.JLabel;

import javax.swing.SwingConstants;

import java.awt.Font;

import javax.swing.JTextArea;

import javax.swing.JScrollBar;

import javax.swing.JScrollPane;

import javax.swing.JComboBox;

import javax.swing.JTextField;

import javax.swing.JButton;

import java.util.Date;

public class jiang1 extends JFrame {

private static final long serialVersionUID = 1L;

private JPanel jContentPane = null;

private JLabel jLabel = null;

private JTextArea jTextArea = null;

private JScrollPane jScrollPane = null;

private JLabel jLabel1 = null;

private JComboBox jComboBox = null;

private JLabel jLabel2 = null;

private JTextField jTextField = null;

private JButton jButton = null;

private JButton jButton1 = null;

private JButton jButton2 = null;

private JButton jButton3 = null;

/** * This is the default constructor */

public jiang1() {

super();

initialize();

}

/** * This method initializes this * *@return void */

private void initialize() {

this.setContentPane(getJContentPane());

this.setTitle("留言板程序");

this.setBounds(new Rectangle(0, 0, 640, 680));

this.setVisible(true);

}

/** * This method initializes jContentPane * *@return javax.swing.JPanel */

private JPanel getJContentPane() {

if (jContentPane == null) {

jLabel2 = new JLabel();

jLabel2.setBounds(new Rectangle(210, 407, 90, 24));

jLabel2.setFont(new Font("Dialog", Font.BOLD, 14));

jLabel2.setText("输入留言:");

jLabel1 = new JLabel();

jLabel1.setBounds(new Rectangle(40, 407, 90, 24));

jLabel1.setFont(new Font("Dialog", Font.BOLD, 14));

jLabel1.setText("选择角色:");

jLabel = new JLabel();

jLabel.setBounds(new Rectangle(283, 15, 45, 20));

jLabel.setHorizontalAlignment(SwingConstants.CENTER);

jLabel.setFont(new Font("Dialog", Font.BOLD, 14));

jLabel.setText("留言板");

jContentPane = new JPanel();

jContentPane.setLayout(null);

jContentPane.add(jLabel, null);

jContentPane.add(getJScrollPane(), null);

jContentPane.add(jLabel1, null);

jContentPane.add(getJComboBox(), null);

jContentPane.add(jLabel2, null);

jContentPane.add(getJTextField(), null);

jContentPane.add(getJButton(), null);

jContentPane.add(getJButton1(), null);

jContentPane.add(getJButton2(), null);

jContentPane.add(getJButton3(), null);

}

return jContentPane;

}

/** * This method initializes jTextArea * *@return javax.swing.JTextArea */

private JTextArea getJTextArea() {

if (jTextArea == null) {

jTextArea = new JTextArea();

jTextArea.setText("留言内容:");

jTextArea.setEditable(false);

}

return jTextArea;

}

/** * This method initializes jScrollPane * *@return javax.swing.JScrollPane */

private JScrollPane getJScrollPane() {

if (jScrollPane == null) {

jScrollPane = new JScrollPane();

jScrollPane.setBounds(new Rectangle(22, 49, 534, 347));

jScrollPane.setViewportView(getJTextArea());

}

return jScrollPane;

}

/** * This method initializes jComboBox * *@return javax.swing.JComboBox */

private JComboBox getJComboBox() {

if (jComboBox == null) {

jComboBox = new JComboBox();

jComboBox.setBounds(new Rectangle(110, 407, 100, 24));

String[] mycbox={"管理员","博主","游客"};

jComboBox.addItem(mycbox[0]);

jComboBox.addItem(mycbox[1]);

jComboBox.addItem(mycbox[2]);

}

return jComboBox;

}

/** * This method initializes jTextField * *@return javax.swing.JTextField */

private JTextField getJTextField() {

if (jTextField == null) {

jTextField = new JTextField();

jTextField.setBounds(new Rectangle(280, 407, 231, 200));

}

return jTextField;

}

/** * This method initializes jButton * *@return javax.swing.JButton */

private JButton getJButton() {

if (jButton == null) {

jButton = new JButton();

jButton.setBounds(new Rectangle(505, 407, 70, 24));

jButton.setText("发帖");

jButton.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {

Date date = new Date();

jTextArea.setText(jTextArea.getText()+"\r\n"+date.toString()+ " " + jComboBox.getSelectedItem().toString()+" 留言:"+jTextField.getText());

}

});

}

return jButton;

}

/** * This method initializes jButton1 * *@return javax.swing.JButton */

private JButton getJButton1() {

if (jButton1 == null) {

jButton1 = new JButton();

jButton1.setBounds(new Rectangle(565, 51, 60, 32));

jButton1.setText("删帖");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {

// jTextArea.setText("留言内容:");

// if(jComboBox.getSelectedItem().toString() == "管理员" || jComboBox.getSelectedItem().toString() =="博主" ){

}

});

}

return jButton1;

}

/** * This method initializes jButton2 * *@return javax.swing.JButton */

private JButton getJButton2() {

if (jButton2 == null) {

jButton2 = new JButton();

jButton2.setBounds(new Rectangle(560, 112, 80, 32));

jButton2.setText("从头浏览");

jButton2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {

jTextArea.setCaretPosition(0);

}

});

}

return jButton2;

}

/** * This method initializes jButton3 * *@return javax.swing.JButton */

private JButton getJButton3() {

if (jButton3 == null) {

jButton3 = new JButton();

jButton3.setBounds(new Rectangle(560, 173, 80, 32));

jButton3.setText("从尾浏览");

jButton3.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {

jTextArea.setCaretPosition((int)jTextArea.getText().length());

}

});

}

return jButton3;

}

public static void main(String args[]){

new jiang1();

}

}

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值