pushcounter.java

来自「关于java的一些课后作业的相关解释 对于初学者还是有一定程度的帮助 希望大」· Java 代码 · 共 47 行

JAVA
47
字号
import javax.swing.JFrame;
public class PushCounter
{
	public static void main (String[] args)
	{  JFrame frame=new JFrame("push counter");
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	frame.getContentPane().add(new PushCounterPanel());
	frame.pack();
	frame.setVisible(true);
	}
}



import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;

public class PushCounterPanel extends JPanel
{private int count;
private JButton push;
private JLabel label;

public PushCounterpanel()
{count=0;

push=new JButton ("push me!");

label=new JLabel("pushes:" +count);

add(push);
add(label);

setPreferredSize(new Dimension(300,400));
setBackground(Color.cyan);
}

private class ButtonListener implements ActionListener
{
{public void actionPerformed(ActionEvent event)
count++;
label.setText("Pushes:"+count);
}
}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?