java关于JFrame添加控件问题... 10
importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclassTest{publicsta...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
TestPanel panel = new TestPanel();
frame.add(panel);
frame.setBounds(100,100,750,450);
frame.setResizable(false);
frame.show();
}
}
class TestPanel extends JPanel
{
JTextField text = new JTextField(16);
JButton btnStart;
JLabel [] Plate = new JLabel[11];//盘子
TestPanel()
{
btnStart = new JButton("开始游戏");
btnStart.addActionListener(new start_Click());
add(btnStart);
}
private void load_plate(int n)
{
for(int i=0;i<n;i++)
{
Plate[i] = new JLabel();
Plate[i].setName("Plate"+i);
}
}
public class start_Click implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
load_plate(Integer.parseInt(text.getText()));
for(int i=0;i<Integer.parseInt(text.getText());i++)
{
//我想在这里将N个Plate标签添加到JPanel大类中、怎么实现?
}
}
}
} 展开
import java.awt.*;
import java.awt.event.*;
public class Test
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
TestPanel panel = new TestPanel();
frame.add(panel);
frame.setBounds(100,100,750,450);
frame.setResizable(false);
frame.show();
}
}
class TestPanel extends JPanel
{
JTextField text = new JTextField(16);
JButton btnStart;
JLabel [] Plate = new JLabel[11];//盘子
TestPanel()
{
btnStart = new JButton("开始游戏");
btnStart.addActionListener(new start_Click());
add(btnStart);
}
private void load_plate(int n)
{
for(int i=0;i<n;i++)
{
Plate[i] = new JLabel();
Plate[i].setName("Plate"+i);
}
}
public class start_Click implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
load_plate(Integer.parseInt(text.getText()));
for(int i=0;i<Integer.parseInt(text.getText());i++)
{
//我想在这里将N个Plate标签添加到JPanel大类中、怎么实现?
}
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询