在不同文件下的两个类,如何用其中一个调用另一个???
其中一个类:import javax.swing.*;
import java.PushCounterPanel;
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");
push.addActionListener(new ButtonListener());
label=new JLabel ("Pushes:"+count);
add(push);
add(label);
setPreferredSize(new Dimension (300,40));
setBackground(Color.cyan);
}
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionListener event)
{
count++;
label.setText("Pushes:"+count);
}
}
}