表白记录代码

效果展示: 

 

 

代码如下:

package 暑假io;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.awt.Color;

public class io {

	private JFrame frame;
	private JTextField textField;
	private JTextField textField_1;
	private JLabel lblNewLabel_1;
	private JLabel lblNewLabel_2;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					io window = new io();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public io() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 728, 488);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		textField = new JTextField();
		textField.setBackground(new Color(255, 204, 255));
		textField.setBounds(273, 246, 252, 38);
		frame.getContentPane().add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setBackground(new Color(255, 255, 204));
		textField_1.setForeground(Color.BLACK);
		textField_1.setBounds(273, 119, 126, 38);
		frame.getContentPane().add(textField_1);
		textField_1.setColumns(10);
		
		lblNewLabel_1 = new JLabel("\u5BF9\u8C01\u8BF4");
		lblNewLabel_1.setFont(new Font("宋体", Font.BOLD, 18));
		lblNewLabel_1.setBounds(171, 180, 86, 35);
		frame.getContentPane().add(lblNewLabel_1);
		
		JTextField textField_2 = new JTextField();
		textField_2.setBackground(new Color(204, 255, 204));
		textField_2.setBounds(273, 179, 126, 38);
		frame.getContentPane().add(textField_2);
		textField_2.setColumns(10);
		
		lblNewLabel_2 = new JLabel("\u8C01\u60F3\u8BF4");
		lblNewLabel_2.setFont(new Font("宋体", Font.BOLD, 18));
		lblNewLabel_2.setBounds(169, 120, 86, 35);
		frame.getContentPane().add(lblNewLabel_2);
		JLabel lblNewLabel = new JLabel("\u60F3\u8BF4\u7684\u8BDD");
		lblNewLabel.setFont(new Font("宋体", Font.BOLD, 18));
		lblNewLabel.setBounds(171, 245, 84, 38);
		frame.getContentPane().add(lblNewLabel);
		
		
		JButton btnNewButton = new JButton("\u4FDD\u5B58");
		btnNewButton.setBackground(new Color(255, 204, 51));
		btnNewButton.setFont(new Font("宋体", Font.BOLD, 19));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String t1=textField_1.getText();
				String t2=textField_2.getText();
			  String string=textField.getText();
			  if(t1.equals("")||t2.equals("")||string.equals("")) {
				JOptionPane.showConfirmDialog(null,"输入框不能为空!","提示",JOptionPane.ERROR_MESSAGE) ; 
			  }
			  else{
			  textField.setText("");
			  textField_1.setText("");
			  textField_2.setText("");
			  try {
				Writer wo=new FileWriter("D:/Test/x1.txt",true);
				wo.write(t1+"想对"+t2+"说:"+string+"\r");
				wo.close();
			} catch (IOException e1) {
				// TODO 自动生成的 catch 块
				e1.printStackTrace();
			}}
			  
				
			}
		});
		btnNewButton.setBounds(261, 330, 119, 38);
		frame.getContentPane().add(btnNewButton);
		
		
	}
}

本人小白,展示了基础代码,图形化界面是eclipse的GUI插件

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值