当前位置: 技术问答>java相关
请教如何通过循环生成控件?如何显示事件触发后生成的控件?可以这样写吗(见内)?谢谢!
来源: 互联网 发布时间:2015-09-12
本文导语: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class tables implements ActionListener { String[] BigProblem={"大问题一","大问题二"}; String[] problem={"问题一","问题二","问题三","问题四","问题五...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class tables implements ActionListener
{
String[] BigProblem={"大问题一","大问题二"};
String[] problem={"问题一","问题二","问题三","问题四","问题五","问题六","问题七",
"问题八","问题九","问题十"};
Font fonts=new Font("宋体",Font.PLAIN,12);
JFrame aWindow=null;
JCheckBox[] checkBox;
JPanel panel=null;
JLabel[] label;
public tables()
{
aWindow=new JFrame("Testing.....");
Container content=aWindow.getContentPane();
Toolkit theKit=aWindow.getToolkit();
Dimension wndSize=theKit.getScreenSize();
aWindow.setBounds(0,0,wndSize.width,wndSize.height);
JButton button1=new JButton("动态生成控件");
button1.setFont(fonts);
button1.addActionListener(this);
panel=new JPanel();
content.add(panel);
panel.add(button1);
aWindow.setVisible(true);
aWindow.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(aWindow,"事件成功","窗体信息",
JOptionPane.PLAIN_MESSAGE);
int big=BigProblem.length;
int small=problem.length;
for(int i=1;i
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class tables implements ActionListener
{
String[] BigProblem={"大问题一","大问题二"};
String[] problem={"问题一","问题二","问题三","问题四","问题五","问题六","问题七",
"问题八","问题九","问题十"};
Font fonts=new Font("宋体",Font.PLAIN,12);
JFrame aWindow=null;
JCheckBox[] checkBox;
JPanel panel=null;
JLabel[] label;
public tables()
{
aWindow=new JFrame("Testing.....");
Container content=aWindow.getContentPane();
Toolkit theKit=aWindow.getToolkit();
Dimension wndSize=theKit.getScreenSize();
aWindow.setBounds(0,0,wndSize.width,wndSize.height);
JButton button1=new JButton("动态生成控件");
button1.setFont(fonts);
button1.addActionListener(this);
panel=new JPanel();
content.add(panel);
panel.add(button1);
aWindow.setVisible(true);
aWindow.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(aWindow,"事件成功","窗体信息",
JOptionPane.PLAIN_MESSAGE);
int big=BigProblem.length;
int small=problem.length;
for(int i=1;i