import java.awt.*;
public class test
{
public static void main(String[] args)
{
Button b[] = {new Button(),new Button(),new Button()};
}
}
public class test
{
public static void main(String[] args)
{
Button b[] = {new Button(),new Button(),new Button()};
}
}
解决方案 »
- 关于类的构造方法的个人理解。。高手进来指点一下!!!
- 一个struts一个Hibernate问题 !!!
- 图像的灰度化
- sun java 上doc文档下载在哪
- 用Java.AWT的TextField文本框,其中部分文字需要设为斜体,怎么办呢??
- 求救:JRUN 的global.jsa有人改过吗?
- 如何看JAVA源代码的问题!!
- 我在读pdf文件时不能读碰到这样一个问题:有谁碰到过这样的问题吗?
- 关于显卡与编程的问题。
- java 中的向量,vector能不能存放非string型的变量
- 请问:think in java 这本书中的reference到底指什么?参数or对象?
- 关于java+oracle的事务处理!
public class test
{
public static void main(String[] args)
{
Button b[] = new Button[10];
for (int i = 0; i < 10; i++) {
b[i] = new Button();
}
}
}
button=new JButton();
JButton[] button;
button=new JButton()[];
>??????????????????
b = new Button()[];
^
test.java:7: ']' expected
b = new Button()[];
^
test.java:7: array required, but java.awt.Button found
b = new Button()[];
^
3 errors
b = new JButton()[];
^
test.java:7: ']' expected
b = new JButton()[];
^
test.java:7: array required, but javax.swing.JButton found
b = new JButton()[];
^
HashMap h;
String ButtonName;//按钮名称,通过这个从HashMap中取出 Button对象 生成: h.put(ButtonName,new Button());
取出: Button a=(Button)h.get(ButtonName);
JButton[] button;
button=new JButton[100];
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class applet5 extends JFrame implements ActionListener
{
JPanel contentPanel=(JPanel)this.getContentPane();
JPanel jp1=new JPanel(new FlowLayout());
JPanel jp2=new JPanel(new FlowLayout());
JButton jb1=new JButton("add");
public applet5() {
super("myJFrame");
this.setSize(400,300);
this.setResizable(false);
this.setLocation(this.getToolkit().getScreenSize().width/2-this.getWidth()/2,this.getToolkit().getScreenSize().height/2-this.getHeight()/2);
contentPanel.setLayout(new BorderLayout());
contentPanel.add("North",jp1);
contentPanel.add("Center",jp2);
jp1.add(jb1);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
jb1.addActionListener(this);
this.setVisible(true);
}public void actionPerformed(ActionEvent e) {
if(e.getSource()==jb1) {
JButton jb2=new JButton("remove_self");
jp2.add(jb2);
jb2.addActionListener(this);
this.validate();
} else {
jp2.remove((JButton)e.getSource());
this.validate();
jp2.repaint();
}
}public static void main(String args[]) {
new applet5();
}
}
new JButton("third")};
//This program obeyed GPL.
//ObjectArray.java
// dynamic object import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class ObjectArray extends JFrame
{
private JButton addButton;
private JButton[] b;
public ObjectArray()
{
setTitle("add button object");
setSize(300,200);
getContentPane().setLayout(new GridLayout());
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
});
addButton=new JButton("Add Button");
addButton.setSize(50,30);
getContentPane().add(addButton);
addButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
b=new JButton[3];
for( int i=0;i<b.length;i++)
{
b[i]=new JButton("button"+i);
getContentPane().add(b[i]);
b[i].repaint();
}
//repaint();
}
});
}
public static void main(String[] args)
{
new ObjectArray().show();
}
}
JButton[] button;
仅是声明了数组button[n]=new JButton();
实例了每个数组中的元素正确的是:
JButton[10] button=new JButton[];
试试看行吗??
记得给我分哦!我没有分用了!