用java创建小程序
dt.add(tf)
语句中的错误是什么?
/*<applet code="applicant" height=300 width=300></applet>*/
import javax.swing.*;
public class applicant extends JApplet
{
static JPanel panel;
JLabel labelAppID;
JLabel labelAppName;
JLabel labelAppAddress;
JLabel labelAppPosition;
JTextField textAppID;
JTextField textAppName;
JTextField textAppAddress;
JComboBox comboAppPosition;
public void init()
{
panel = new JPanel();
getContentPane().add(panel);
labelAppID=new JLabel("Applicant ID");
labelAppName=new JLabel("Name");
labelAppAddress=new JLabel("Address");
labelAppPosition=new JLabel("Position");
textAppID=new JTextField(5);
textAppName=new JTextField(30);
textAppAddress=new JTextField(30);
String positions[]={"Manager", "Executive", "Associate"};
comboAppPosition=new JComboBox(positions);
panel.add(labelAppID);
panel.add(textAppID);
panel.add(labelAppName);
panel.add(textAppName);
panel.add(labelAppAddress);
panel.add(textAppAddress);
panel.add(labelAppPosition);
panel.add(comboAppPosition);
setTitle("JToolBar as a Tool Palette - Example");
JPanel jp=(JPanel)getContentPane();
jp.setLayout(new BorderLayout());
JDesktopPane dt=new JDesktopPane();
dt.setBackground(jp.getBackground());
jp.add("center",dt);
JFrame tf=new JFrame("Tools");
dt.add(tf);
}
}
What is the error in dt.add(tf)
statement?
/*<applet code="applicant" height=300 width=300></applet>*/
import javax.swing.*;
public class applicant extends JApplet
{
static JPanel panel;
JLabel labelAppID;
JLabel labelAppName;
JLabel labelAppAddress;
JLabel labelAppPosition;
JTextField textAppID;
JTextField textAppName;
JTextField textAppAddress;
JComboBox comboAppPosition;
public void init()
{
panel = new JPanel();
getContentPane().add(panel);
labelAppID=new JLabel("Applicant ID");
labelAppName=new JLabel("Name");
labelAppAddress=new JLabel("Address");
labelAppPosition=new JLabel("Position");
textAppID=new JTextField(5);
textAppName=new JTextField(30);
textAppAddress=new JTextField(30);
String positions[]={"Manager", "Executive", "Associate"};
comboAppPosition=new JComboBox(positions);
panel.add(labelAppID);
panel.add(textAppID);
panel.add(labelAppName);
panel.add(textAppName);
panel.add(labelAppAddress);
panel.add(textAppAddress);
panel.add(labelAppPosition);
panel.add(comboAppPosition);
setTitle("JToolBar as a Tool Palette - Example");
JPanel jp=(JPanel)getContentPane();
jp.setLayout(new BorderLayout());
JDesktopPane dt=new JDesktopPane();
dt.setBackground(jp.getBackground());
jp.add("center",dt);
JFrame tf=new JFrame("Tools");
dt.add(tf);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以将 JInternalFrame 添加到 JDesktopPane,而 JFrame 则不能。
有关更多详细信息,请参阅 Java 教程中的如何使用内部框架 。
A JInternalFrame can be added to a JDesktopPane, whereas a JFrame cannot.
See How to Use Internal Frames in the Java Tutorial for further details.