java中按钮重新开始代码_java大作业 下面是我的代码,求大神帮忙添加一个重新开始的按钮并实现这个按钮的功能...

packagedictionary;importjava.awt.Dimension;importjava.awt.FlowLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JButton;import...

package dictionary;

import java.awt.Dimension;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JTextField;

public class yingyu extends JFrame implements ActionListener{

private JTextField word;

private JLabel label;

private JButton next;

private int index = 0;

private String[] words;

private int score = 0;

public yingyu(){

words = new String[] {"苹果", "香蕉", "狗", "猫", "水"};

word = new JTextField();

Dimension size = new Dimension(60, 30);

word.setPreferredSize(size );

label = new JLabel(words[0]);

next = new JButton("下一道");

next.addActionListener(this);

this.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3));

this.add(label);

this.add(word);

this.add(next);

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

this.setVisible(true);

}public static void main(String[] args){

new yingyu();

}

public void reload(){

label.setText(words[index]);

repaint();

}

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值