啊啊啊,我的第一个java swing程序

我嚯,我的第一个java图形界面小程序,纪念一下大笑


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Work extends JFrame implements ActionListener
{
	JLabel label1,label2,label3;
	JTextField text,he,want_erase;
	String s;
	public int flag = 0;
	public Container c;
	public Work()
	{
		super("my work");
		c = new Container();
		he = new JTextField();
		setLocation(600,300);
		setSize(500,300);
		setLayout(new GridLayout(8,1,10,10));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		text = new JTextField();
		label1 = new JLabel("请输入字符串:");
		getContentPane().add(label1);
		getContentPane().add(text);
		label2 = new JLabel("请输入你想要删除的字符:");
		getContentPane().add(label2);
		want_erase = new JTextField();
		want_erase.addActionListener(this);
		getContentPane().add(want_erase);
		label3 = new JLabel("最后结果是:");
		getContentPane().add(label3);
		getContentPane().add(he);
		setVisible(true);
	}
	public static void main(String args[])
	{
		new Work();
	}
	public void actionPerformed(ActionEvent e)
	{
		s = want_erase.getText();
		if(s.length()>1)
		{
			he.setText("你输入有误!");
		}
		else
		{
			String ss = new String();
			int k=0;
			String s1 = text.getText();
			char ch = s.charAt(0);
			for(int i = 0;i<s1.length();i++)
			{
				if(s1.charAt(i)==ch)
					continue;
				else
					ss=ss+s1.charAt(i);
			}
			he.setText(ss);
		}
		this.setVisible(true);
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值