我已经扭转了但得到一个编译错误 PLZ HELP 需要在今天晚上 10:00 之前得到答案,因为这是由于今晚
我在执行反向按钮操作时遇到编译错误:找不到符号词 - 如何解决该问题
这是源代码:
public class ReverseTester extends JFrame
{
private static final int FRAME_WIDTH = 500;
private static final int FRAME_HEIGHT = 200;
private JTextField txtInstring;
private JLabel lblOutstring;
private JButton btnReverse;
private JButton btnExit;
private JPanel pnl2x3;
public ReverseTester()
{
txtInstring = new JTextField("");
lblOutstring = new JLabel("Reversed LinkedList: ");
btnReverse = new JButton("Reverse");
ActionListener my_ReverseListener = new ReverseListener();
btnReverse.addActionListener(my_ReverseListener);
btnExit = new JButton("Exit");
ActionListener my_ExitListener = new ExitButtonListener();
btnExit.addActionListener(my_ExitListener);
pnl2x3 = new JPanel();
pnl2x3.setLayout (new GridLayout(2,1));
pnl2x3.add(txtInstring);
pnl2x3.add(btnReverse);
pnl2x3.add(btnExit);
pnl2x3.add(lblOutstring);
add(pnl2x3, BorderLayout.CENTER);
setSize(FRAME_WIDTH, FRAME_HEIGHT);
}
public static void main(String[] args)
{
LinkedList<String> words = new LinkedList<String>();
words.addLast("before...");
words.addLast("gone");
words.addLast("has");
words.addLast("one");
words.addLast("no");
words.addLast("where");
words.addLast("go");
words.addLast("boldly");
words.addLast("To");
words.addLast("frontier.");
words.addLast("final");
words.addLast("the");
words.addLast("is");
words.addLast("Space");
String instring = String.format("%s",words);
ListUtil.reverse(words);
JFrame frame = new ReverseTester();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
class ExitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
dispose();
}
}
class ReverseListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String outstring = String.format("%s",words);
outstring = outstring.replace(",", "");
lblOutstring.setText(outstring);
}
}
}
public class ListUtil
{
public static void reverse(LinkedList<String> myList)
{
LinkedList<String> temp = new LinkedList<String>();
for (String element : myList)
{
//String removed = myList.removeFirst();
temp.addFirst(element);
String outstring_rev = String.format("%s",temp);
outstring_rev = outstring_rev.replace(",", "");
}
}
}