Ошибка в коде - Java (241054)
Формулировка задачи:
Задача про шифр Гронсфельда
в этом коде подчеркнул
new ButtonExitListener(this));new ButtonDecodeListener(this));new ButtonCodeListener(this));
Есть ссылки на отдельный класс для каждого, но подчеркивает красным, когда ссылаешься Cipher.this.setVisible(false);
Cipher.this.dispose();
Исправьте пожалуйста ошибку)Заранее спасибо.
package grow;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Cipher
extends JFrame {
private JLabel labelOutput;
private JTextField textFieldInput;
private JTextField textFieldKey;
private JTextField textFieldOutput;
static Cipher app;
public Cipher() {
super("\u0428\u0438\u0444\u0440");
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
this.setBounds((dim.width - 450) / 2, (dim.height - 250) / 2, 450, 250);
JLabel labelInput = new JLabel("\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043a\u0441\u0442:");
JLabel labelKey = new JLabel("\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043a\u043b\u044e\u0447:");
this.labelOutput = new JLabel("");
this.textFieldInput = new JTextField(20);
this.textFieldKey = new JTextField(15);
this.textFieldOutput = new JTextField(20);
JButton buttonCode = new JButton("\u0417\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c");
JButton buttonDecode = new JButton("\u0420\u0430\u0441\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c");
JButton buttonExit = new JButton("\u0412\u044b\u0445\u043e\u0434");
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints opt = new GridBagConstraints();
opt.gridx = 0;
opt.gridy = 0;
opt.anchor = 17;
opt.insets = new Insets(5, 5, 5, 5);
panel.add((Component)labelInput, opt);
++opt.gridx;
panel.add((Component)this.textFieldInput, opt);
--opt.gridx;
++opt.gridy;
panel.add((Component)labelKey, opt);
++opt.gridx;
panel.add((Component)this.textFieldKey, opt);
this.labelOutput.setVisible(false);
this.textFieldOutput.setVisible(false);
--opt.gridx;
++opt.gridy;
panel.add((Component)this.labelOutput, opt);
++opt.gridx;
panel.add((Component)this.textFieldOutput, opt);
--opt.gridx;
++opt.gridy;
panel.add((Component)buttonCode, opt);
++opt.gridx;
panel.add((Component)buttonDecode, opt);
opt.gridwidth = 2;
opt.anchor = 10;
--opt.gridx;
++opt.gridy;
panel.add((Component)buttonExit, opt);
this.add((Component)panel);
buttonCode.addActionListener((ActionListener)new ButtonCodeListener(this));
buttonDecode.addActionListener((ActionListener)new ButtonDecodeListener(this));
buttonExit.addActionListener((ActionListener)new ButtonExitListener(this));
this.setDefaultCloseOperation(3);
}
public static void main(String[] args) {
app = new Cipher();
app.setVisible(true);
}
static /* synthetic */ JTextField access$0(Cipher cipher) {
return cipher.textFieldKey;
}
static /* synthetic */ JTextField access$1(Cipher cipher) {
return cipher.textFieldInput;
}
static /* synthetic */ JTextField access$2(Cipher cipher) {
return cipher.textFieldOutput;
}
static /* synthetic */ JLabel access$3(Cipher cipher) {
return cipher.labelOutput;
}
}package grow;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ButtonExitListener
implements ActionListener {
@Override
public void actionPerformed(ActionEvent arg0) {
Cipher.this.setVisible(false);
Cipher.this.dispose();
}
}Решение задачи: «Ошибка в коде»
textual
Листинг программы
buttonExit.addActionListener(new ButtonExitListener(this));