2013-03-20 4 views
3

그래서 Sudoku 해결사를 완성했지만 개선하고 싶습니다. 이렇게하려면 어떻게 든 documentListener에서 내 betterJTextField에 도달해야합니다. documentListener을 사용하여 betterJTextFields에서 실시간으로 읽을 수 있습니다. 문제는 insertUpdate(DocumentEvent e)입니다.DocumentListener에서 JTextField에 도달

은 내가 DocumentEvent가에서 일어난 betterJTextfield에 도달해야합니다. 예를 들어, 잘못된 입력되면, betterJTextfield 등 적색으로 바뀌고

내가 가진 내 모든 당신이 알 필요가 있다면 매트릭스에서 betterJTextfield. 모든 필드는 스도쿠에서 하나의 숫자를 처리합니다.

@Override 
    public void insertUpdate(DocumentEvent e) { 

     //Removed code which checks if the input in the betterJTextField is fine. 

    } 

(JFormattedTextfield이 확장 JTextField)

public class betterJTextField extends JFormattedTextField { 
private int row; 
private int column; 

public betterJTextField(Format format, int row, int column) { 
    super(format); 
    this.row = row; 
    this.column = column; 
    // TODO Auto-generated constructor stub 
} 

public int getRow() { 
    return row; 
} 

public int getColumn() { 
    return column; 
} 

답변

2

난 정말 당신이 요구하는 것을 완전히 이해하지 않지만, 나는 이것이 당신이 찾고있는 생각 : 놀라운

private static class RedDocumentListener implements DocumentListener { 
    private JTextField textField; 

    public RedDocumentListener(JTextField textField) { 
     this.textField = textField; 
    } 
    @Override 
    public void insertUpdate(DocumentEvent e) { 
     textField.setBackground(Color.red); 
    } 
    @Override 
    public void removeUpdate(DocumentEvent e) { 
     textField.setBackground(Color.red); 
    } 
    @Override 
    public void changedUpdate(DocumentEvent e) { 
     textField.setBackground(Color.red); 
    } 
} 
+0

, 고맙습니다. 왜 그렇게 생각하지 않았어 :) – Jakkra