0
내가 findBugs가 설치되어 있고 경고가 기록되지 않은 필드가 말한다스윙 기록되지 않은 필드 경고 (자바)
if (source == this.temp)
if 문에서 actionPerformed 메소드 버그 경고를 얻을. 프로그램은 여전히 컴파일되지만 temp라는 버튼을 클릭하면 멈 춥니 다.
나는 그 필드를 이미 올바르게 초기화했다고 생각했습니다. 누군가 내가 엉망인 곳을 안내 할 수 있습니까? 당신이 코드의이 비트가 생성자에서 감사
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;
import components.simplereader.SimpleReader;
import components.simplereader.SimpleReader1L;
/**
* View class.
*
* @author Redacted
*/
@SuppressWarnings("serial")
public final class PasswordManagerView1 extends JFrame
implements PasswordManagerView {
private JButton temp;
/**
* controller.
*/
private PasswordManagerController controller;
/**
* Jpanel.
*/
/**
* Useful constants.
*/
private Dimension maxSize;
private JTabbedPane tabbedPane;
/**
* Constructor.
*/
public PasswordManagerView1() {
super("Password Manager");
JTabbedPane tabbedPane = new JTabbedPane();
//Initial JPanel creation
tabbedPane.setBorder(new EmptyBorder(5, 5, 5, 5));
//tabbedPane.setLayout(new BorderLayout(0, 0));
this.maxSize = new Dimension(700, 300);
tabbedPane.setPreferredSize(this.maxSize);
this.getContentPane().add(tabbedPane);
//Initial JTabbedPane creation
//Tab creation
JComponent panel1 = this.makeTextPanel("temp1");
ImageIcon icon = new ImageIcon("lock-icon.png");
tabbedPane.addTab("Add Password", icon, panel1,
"Adds a password to the vault");
JComponent panel2 = this.makeTextPanel("temp2");
tabbedPane.addTab("Delete Password", icon, panel2,
"Deletes a password from the vault");
JComponent panel3 = this.makeTextPanel("temp3");
tabbedPane.addTab("Password Vault", icon, panel3,
"View the passwords in the vault");
JComponent panel4 = this.makeInfoPanel();
tabbedPane.addTab("Info/Settings", icon, panel4,
"View settings and program info");
JButton temp = new JButton("Hey");
panel1.add(temp);
temp.addActionListener(this);
//Pack up
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
private JComponent makeTextPanel(String text) {
JPanel panel = new JPanel();
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
private JComponent makeInfoPanel() {
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(1, 1));
StringBuilder toPrint = new StringBuilder();
SimpleReader in = new SimpleReader1L("data/Notice.txt");
while (!in.atEOS()) {
toPrint.append(in.nextLine() + "\n");
}
String toPrintString = toPrint.toString();
JTextArea noticeText = new JTextArea(toPrintString);
noticeText.setEditable(false);
JScrollPane noticeTextScroll = new JScrollPane(noticeText);
panel.add(noticeTextScroll);
in.close();
return panel;
}
@Override
public void registerObserver(PasswordManagerController controller) {
this.controller = controller;
}
@Override
public void actionPerformed(ActionEvent event) {
//Wait cursor
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
//What button was pressed
Object source = event.getSource();
if (source == this.temp) {
this.controller.processTestEvent();
}
}
아, 그렇게 간단한 실수입니다. 고맙습니다. 이 코드가 적절하게 스타일 화 된 것처럼 보이는가? – frillybob
@frillybob : 코드 검토에 더 많은 질문이 있습니다. http://codereview.stackexchange.com/ -하지만 이름의 IMO 번호는 큰 숫자입니다. 주석은 코드의 기능에 많은 것을 추가하지 않습니다 (비록 당신이 배우고 있다면 OK), 모든 코드 그룹 (예 : 탭 생성)은 자신의 기능을 사용할 수 있습니다. – mszymborski
@mszymborski FYI [codereview.se]에 버그가 있거나 작동하지 않는 것에 대해 언급하는 질문은 수 분 내에 종료됩니다. 그러나 일단 코드가 작동하면 코드의 모든 측면에 대한 피드백을 위해 CR에 게시해야합니다. –