JPanel没有出现,编译很好 import javax.swing.*; 导入java.awt.*; 导入java.awt.event.ActionEvent; 导入java.awt.event.ActionListener; 导入java.util.logging.*; 公共类NewAccountApplet扩展JApplet实现ActionListener{ /** * */ 私有静态最终长serialVersionUID=1L; JLabel滴定法; JLabel[]txt; JTextField[]联合特遣部队; 接受,拒绝; JPanel jp1、jp2、jp3、jp4、jp5、jp6; 字符串[]accountlist={“选择帐户类型”,“客户”,“管理员”}; JComboBox textAlignment=新的JComboBox(accountlist); GridLayout productLO=新的GridLayout(10,4,10,10); 整数数量=5; JComboBox[]选择数量; 公共void init(){ 设置大小(400400); JPanel content=(JPanel)getContentPane(); GridBagConstraints firstCol=新的GridBagConstraints(); firstCol.weightx=1.0; firstCol.anchor=gridbagstraints.WEST; 第一列插图=新插图(5,20,5,5); GridBagConstraints lastCol=新的GridBagConstraints(); lastCol.gridwidth=GridBagConstraints.Requirement; lastCol.weightx=1.0; lastCol.fill=GridBagConstraints.HORIZONTAL; lastCol.insets=新的插图(5,5,5,20); 字符串[]labelText={“名称”、“帐户ID”、“密码”、“电子邮件”、“电话”、“地址”、“帐户类型”}; titlePage=new JLabel(“创建新帐户”); txt=新的JLabel[9]; jtf=新的JTextField[9]; 接受=新的JButton(“创建”); 拒绝=新按钮(“拒绝”); jp1=新的JPanel(); jp2=新的JPanel(新的GridBagLayout()); jp3=新的JPanel(); jp4=新的JPanel(); jp5=新的JPanel(); jp6=新的JPanel(); 对于(int i=0;(i
您没有向任何内容添加JPanel没有出现,编译很好 import javax.swing.*; 导入java.awt.*; 导入java.awt.event.ActionEvent; 导入java.awt.event.ActionListener; 导入java.util.logging.*; 公共类NewAccountApplet扩展JApplet实现ActionListener{ /** * */ 私有静态最终长serialVersionUID=1L; JLabel滴定法; JLabel[]txt; JTextField[]联合特遣部队; 接受,拒绝; JPanel jp1、jp2、jp3、jp4、jp5、jp6; 字符串[]accountlist={“选择帐户类型”,“客户”,“管理员”}; JComboBox textAlignment=新的JComboBox(accountlist); GridLayout productLO=新的GridLayout(10,4,10,10); 整数数量=5; JComboBox[]选择数量; 公共void init(){ 设置大小(400400); JPanel content=(JPanel)getContentPane(); GridBagConstraints firstCol=新的GridBagConstraints(); firstCol.weightx=1.0; firstCol.anchor=gridbagstraints.WEST; 第一列插图=新插图(5,20,5,5); GridBagConstraints lastCol=新的GridBagConstraints(); lastCol.gridwidth=GridBagConstraints.Requirement; lastCol.weightx=1.0; lastCol.fill=GridBagConstraints.HORIZONTAL; lastCol.insets=新的插图(5,5,5,20); 字符串[]labelText={“名称”、“帐户ID”、“密码”、“电子邮件”、“电话”、“地址”、“帐户类型”}; titlePage=new JLabel(“创建新帐户”); txt=新的JLabel[9]; jtf=新的JTextField[9]; 接受=新的JButton(“创建”); 拒绝=新按钮(“拒绝”); jp1=新的JPanel(); jp2=新的JPanel(新的GridBagLayout()); jp3=新的JPanel(); jp4=新的JPanel(); jp5=新的JPanel(); jp6=新的JPanel(); 对于(int i=0;(i,java,swing,Java,Swing,您没有向任何内容添加jp5) 您可以通过添加System.out.println(“parent=“+jp5.getParent());方法中的任何位置来测试这一点 在小程序中使用System.exit(0);无法“退出”小程序 这将是一个非常好的应用程序用例 LI>您应该考虑将每个“筛选器”分隔为它自己的类/ jPATA/COD>,而不是将所有东西填充到一个类中。 您没有向任何内容添加jp5 您可以通过添加System.out.println(“parent=“+jp5.getParent
jp5
)
您可以通过添加System.out.println(“parent=“+jp5.getParent());
方法中的任何位置来测试这一点
- 在小程序中使用
无法“退出”小程序System.exit(0);
- 这将是一个非常好的应用程序用例 <> LI>您应该考虑将每个“筛选器”分隔为它自己的类/<代码> jPATA/COD>,而不是将所有东西填充到一个类中。
- 您没有向任何内容添加
jp5
您可以通过添加System.out.println(“parent=“+jp5.getParent());
方法中的任何位置来测试这一点
- 在小程序中使用
无法“退出”小程序System.exit(0);
- 这将是一个非常好的应用程序用例 <> LI>您应该考虑将每个“筛选器”分隔为它自己的类/<代码> jPATA/COD>,而不是将所有东西填充到一个类中。
jp6
。您也没有在代码中的任何位置添加jp6
。
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.*;
public class NewAccountApplet extends JApplet implements ActionListener{
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel titlePage;
JLabel[] txt;
JTextField[] jtf;
JButton accept, decline;
JPanel jp1, jp2, jp3, jp4, jp5, jp6;
String[] accountlist = {"Select Account Type.", "Customer", "Admin"};
JComboBox<Object> textAlignment = new JComboBox<Object>(accountlist);
GridLayout productLO = new GridLayout(10,4,10,10);
int qty = 5;
JComboBox<Object>[] selectQty;
public void init(){
setSize(400,400);
JPanel content = (JPanel)getContentPane();
GridBagConstraints firstCol = new GridBagConstraints();
firstCol.weightx = 1.0;
firstCol.anchor = GridBagConstraints.WEST;
firstCol.insets = new Insets(5, 20, 5, 5);
GridBagConstraints lastCol = new GridBagConstraints();
lastCol.gridwidth = GridBagConstraints.REMAINDER;
lastCol.weightx = 1.0;
lastCol.fill = GridBagConstraints.HORIZONTAL;
lastCol.insets = new Insets(5, 5, 5, 20);
String[] labeltxt = {"Name","Account ID","Password","E-Mail","Phone","Address","","","Account Type"};
titlePage = new JLabel("Create New Account");
txt = new JLabel[9];
jtf = new JTextField[9];
accept = new JButton("Create");
decline = new JButton("Decline");
jp1 = new JPanel();
jp2 = new JPanel(new GridBagLayout());
jp3 = new JPanel();
jp4 = new JPanel();
jp5 = new JPanel();
jp6 = new JPanel();
for(int i=0; (i<9); i++) {
txt[i] = new JLabel();
txt[i].setText(labeltxt[i]);
jp2.add(txt[i], firstCol);
jtf[i] = new JTextField();
jtf[i].setPreferredSize(new Dimension(300, 20));
jp2.add(jtf[i], lastCol);
}
jp1.add(titlePage);
jp3.add(accept);
jp3.add(decline);
content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
content.add(jp1);
content.add(jp2);
content.add(jp3);
String id = this.jtf[1].getText();
String pw = this.jtf[2].getText();
jtf[6].setText(id);
jtf[7].setText(pw);
jtf[6].setVisible(false);
jtf[7].setVisible(false);
jtf[8].setVisible(false);
jp2.add(textAlignment, lastCol);
decline.addActionListener(this);
accept.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
String id = jtf[1].getText();
String pw = jtf[2].getText();
String checkID = jtf[6].getText();
String checkPW = jtf[7].getText();
String accountType = "";
String correctType = "Customer";
String chosenType = (String) textAlignment.getSelectedItem();
JPasswordField pField = new JPasswordField(10);
JPanel pPanel = new JPanel();
pPanel.add(new JLabel("Please Enter Password: "));
pPanel.add(pField);
if (e.getActionCommand().equals("Create") && (chosenType.equals("Customer"))){
JOptionPane.showMessageDialog(null, "Thank you for Joining!");
id = jtf[1].getText();
pw = jtf[2].getText();
titlePage.setText("Welcome to Final Sales!");
accept.setText("Login");
decline.setText("Cancel");
txt[6].setText("UserName");
txt[7].setText("Password");
jtf[0].setText("");
jtf[3].setText("");
jtf[4].setText("");
jtf[5].setText("");
txt[0].setVisible(false);
txt[1].setVisible(false);
txt[2].setVisible(false);
txt[3].setVisible(false);
txt[4].setVisible(false);
txt[5].setVisible(false);
textAlignment.setVisible(false);
txt[8].setVisible(false);
jtf[0].setVisible(false);
jtf[1].setVisible(false);
jtf[2].setVisible(false);
jtf[3].setVisible(false);
jtf[4].setVisible(false);
jtf[5].setVisible(false);
jtf[6].setVisible(true);
jtf[7].setVisible(true);
}
if (e.getActionCommand().equals("Create") && (chosenType.equals("Admin"))) {
JOptionPane.showMessageDialog(null, pPanel);
JOptionPane.showMessageDialog(null, "Wrong Admin Password");
}
if (e.getActionCommand().equals("Create") && (chosenType.equals("Select Account Type."))) {
JOptionPane.showMessageDialog(null, "You have selected wrong account type.");
}
if (e.getActionCommand().equals("Decline"))
System.exit(0);
if (e.getActionCommand().equals("Login")) {
if (id.equals(checkID) && pw.equals(checkPW)) {
JOptionPane.showMessageDialog(null, "Authenticated");
JPanel content = (JPanel)getContentPane();
GridBagConstraints firstCol = new GridBagConstraints();
firstCol.weightx = 1.0;
firstCol.anchor = GridBagConstraints.WEST;
firstCol.insets = new Insets(5, 20, 5, 5);
GridBagConstraints lastCol = new GridBagConstraints();
lastCol.gridwidth = GridBagConstraints.REMAINDER;
lastCol.weightx = 1.0;
lastCol.fill = GridBagConstraints.HORIZONTAL;
lastCol.insets = new Insets(5, 5, 5, 20);
selectQty = new JComboBox[qty];
jp1.setVisible(false);
jp2.setVisible(false);
jp3.setVisible(false);
jp4.setVisible(true);
jp5.setVisible(true);
jp6.setVisible(true);
String[] itemText = {"White Snapback", "Silver Necklace", "Black T Shirt", "", "5"};
JLabel[] items = new JLabel[5];
JLabel purchasePage = new JLabel("Items for Purchase");
jp4.add(purchasePage);
content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
content.add(jp4);
jp4 = new JPanel();
jp5.setLayout(new GridBagLayout());
jp6 = new JPanel();
for(int i=0; (i<items.length); i++) {
items[i] = new JLabel();
items[i].setText(itemText[i]);
jp5.add(items[i], firstCol);
selectQty[i] = new JComboBox<Object>();
selectQty[i].setPreferredSize(new Dimension(300, 20));
jp5.add(selectQty[i], lastCol);
}
}
else JOptionPane.showMessageDialog(null, "Wrong account information");}
if (e.getActionCommand().equals("Cancel")) {
System.exit(0);}
}
}