编写Java程序时,Java可以';在数组中找不到我的符号?。需要帮助吗
可能重复:编写Java程序时,Java可以';在数组中找不到我的符号?。需要帮助吗,java,arrays,compiler-construction,methods,Java,Arrays,Compiler Construction,Methods,可能重复: 我得到这个错误 我在做一个GUI程序,我遇到的问题是创建一个代码,当用户选择某个东西时,动作就会发生 例如,选择一顿饭,总费用将更改为2500 Main.java:155: cannot find symbol symbol : variable isSeletecd location: class java.lang.String if (dorm[0].isSeletecd && meal[0].isSeletecd()) ^. do
我得到这个错误 我在做一个GUI程序,我遇到的问题是创建一个代码,当用户选择某个东西时,动作就会发生 例如,选择一顿饭,总费用将更改为2500
Main.java:155: cannot find symbol
symbol : variable isSeletecd
location: class java.lang.String
if (dorm[0].isSeletecd && meal[0].isSeletecd())
^.
dorm是一个字符串数组,方法isSelected和setSelected(无论如何拼写)对于字符串来说都没有意义。阅读有关如何使用JComboBox的教程,了解如何正确使用它们。你可以在这里找到它:不要只是重复问题。如果你在理解答案时有问题,请添加评论。我4小时前刚刚回答了你的问题。如果您仍然有问题,请尝试更改问题。告诉我们你已经尝试了什么,你正试图实现什么。看在上帝的份上,请阅读@user599272,你在这里想做什么,投的反对票比问题还多?天哪,你之前的问题已经告诉过你了,这是一个你选择忽略的建议。为什么您忽略了在前面的线程中提出的建议,如果您只是忽略了帮助,我们为什么还要继续尝试帮助您?如果你不明白答案,那就说点什么,但不要只是再问这个问题,让我们浪费时间。
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
The Main class creates the GUI for the Dorm and
Meal charges.
*/
public class Main extends JFrame
{
private JPanel dormPanel;
private JComboBox dormBox;
private JPanel mealPanel;
private JComboBox mealBox;
private JPanel totalChargesPanel;
private JPanel selectedMealPanel;
private JPanel buttonPanel;
private JButton calcButton;
private JLabel label1;
private JTextField totalCharges;
private String[] dorm = { "Allen Hall: $1,500 per semester",
"Pike Hall: $1,600 per semester",
"Farthing Hall: $1,200 per semester",
"University Suites: $1,800 pe r semester"};
private String[] meal = { "7 meals per week: $650 per semester",
"14 meals per week: $1,095 per semester",
"Unlimited meals: $1,500 per semester"};
/**
Constructor
*/
public Main()
{
super("Dormitory and Meal Plan");
// Specify an action for the close button.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create a BorderLayout manager.
setLayout(new BorderLayout());
// Create the dorm and meal panel.
buildDormPanel();
buildMealPanel();
buildSelectedTotalChargesPanel();
buildButtonPanel();
// Add the components to the content pane.
add(dormPanel, BorderLayout.WEST);
add(mealPanel, BorderLayout.EAST);
add(totalChargesPanel, BorderLayout.SOUTH);
add(buttonPanel, BorderLayout.NORTH);
// Pack the contents of the window and display it.
pack();
setVisible(true);
}
// The buildDormPanel method builds the dorm panel.
private void buildDormPanel()
{
// Create the dorm panel.
dormPanel = new JPanel();
dormBox = new JComboBox(dorm);
// Register the action listener.
dormBox.addActionListener(new ComboBoxListener());
// Add the dorm panel to the panel.
dormPanel.add(dormBox);
}
// The buildMealPanel method builds the meal panel.
private void buildMealPanel()
{
// Create the meal panel.
mealPanel = new JPanel();
mealBox = new JComboBox(meal);
// Register the action listener.
mealBox.addActionListener(new ComboBoxListener());
// Add the meal panel to the panel.
mealPanel.add(mealBox);
}
// The buttonPanel method builds the bottun panel.
private void buildButtonPanel()
{
// Create a panel.
buttonPanel = new JPanel();
// Create a button.
calcButton = new JButton("Calculate");
// Register an action listener with the button.
calcButton.addActionListener(new ButtonListener());
// Add the button to the panel.
buttonPanel.add(calcButton);
}
// The buildSelectedDormPanel builds the selected totalCharges panel.
private void buildSelectedTotalChargesPanel()
{
// Create the totalChargesPanel for the label.
totalChargesPanel = new JPanel();
label1 = new JLabel("Total charges per semester: ");
// Create the totalCharges textfield.
totalCharges = new JTextField (25);
totalCharges.setEditable(false);
// Add the totalChargesPanel to the panel.
totalChargesPanel.add(label1);
totalChargesPanel.add(totalCharges);
}
/** Private inner class that handles the event when the user
selects the dorm and meal boxes.
*/
private class ComboBoxListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// Variables to hold the dorm, meal, and total charges.
String dorm = (String) dormBox.getSelectedItem();
String meal = (String) mealBox.getSelectedItem();
// Calculates the total.
totalCharges.setText(meal + dorm);
}
}
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (dorm[0].isSeletecd && meal[0].isSeletecd())
totalCharges.setText("2150.00");
if (dorm[0].isSeletecd && meal[1].isSeletecd())
totalCharges.setText("2595.00");
if (dorm[0].isSeletecd && meal[2].isSeletecd())
totalCharges.setText("3000.00");
if (dorm[1].isSeletecd && meal[0].isSeletecd())
totalCharges.setText("2250.00");
if (dorm[1].isSeletecd && meal[1].isSeletecd())
totalCharges.setText("2695.00");
if (dorm[1].isSeletecd && meal[2].isSeletecd())
totalCharges.setText("3100.00");
if (dorm[2].isSeletecd && meal[0].isSeletecd())
totalCharges.setText("1850.00");
if (dorm[2].isSeletecd && meal[1].isSeletecd())
totalCharges.setText("2295.00");
if (dorm[2].isSeletecd && meal[2].isSeletecd())
totalCharges.setText("2700.00");
if (dorm[3].isSeletecd && meal[0].isSeletecd())
totalCharges.setText("2450.00");
if (dorm[3].isSeletecd && meal[1].isSeletecd())
totalCharges.setText("2895.00");
if (dorm[3].isSeletecd && meal[2].isSeletecd())
totalCharges.setText("3300.00");
}
}
public static void main(String[] args)
{
new Main();
}
}