diff --git a/src/CurScreen.java b/src/CurScreen.java index 5304da1..b898928 100644 --- a/src/CurScreen.java +++ b/src/CurScreen.java @@ -76,11 +76,11 @@ String temp_if9; if ((state==0)) { String temp_if8; - if ((!company.equals("")&&!(businessCardManagement.containsKey(company)))) { - temp_if8 = "企業一覧"; - } else { - temp_if8 = "企業一覧"; - } + if ((!company.equals("")&&!(businessCardManagement.containsKey(company)))) { + temp_if8 = "企業一覧"; + } else { + temp_if8 = "企業一覧"; + } temp_if9 = temp_if8; } else { temp_if9 = this.value; diff --git a/src/SwingPresenter.java b/src/SwingPresenter.java index 3ff70ef..6a3d9d6 100644 --- a/src/SwingPresenter.java +++ b/src/SwingPresenter.java @@ -1,5 +1,9 @@ import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import javax.swing.table.DefaultTableModel; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; import java.awt.Component; import java.awt.FlowLayout; import java.awt.event.MouseEvent; @@ -38,23 +42,36 @@ JTextField textField = new JTextField(10); mainPanel.add(textField); components.put(key, textField); - textField.addMouseListener(new MouseListener() { + textField.getDocument().addDocumentListener(new DocumentListener() { @Override - public void mouseClicked(MouseEvent e) { + public void insertUpdate(DocumentEvent e) { + Document d = e.getDocument(); + try { + String text = d.getText(0, d.getLength()); + main.textEvent(key, text); + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } } @Override - public void mousePressed(MouseEvent e) { - main.mouseEvent(key, 1); + public void removeUpdate(DocumentEvent e) { + Document d = e.getDocument(); + try { + String text = d.getText(0, d.getLength()); + main.textEvent(key, text); + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } } @Override - public void mouseReleased(MouseEvent e) { - main.mouseEvent(key, 0); - } - @Override - public void mouseEntered(MouseEvent e) { - } - @Override - public void mouseExited(MouseEvent e) { + public void changedUpdate(DocumentEvent e) { + Document d = e.getDocument(); + try { + String text = d.getText(0, d.getLength()); + main.textEvent(key, text); + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } } }); } else if (type.equals("label")) { @@ -175,23 +192,36 @@ textField.setSize(width, height); mainPanel.add(textField); components.put(key, textField); - textField.addMouseListener(new MouseListener() { + textField.getDocument().addDocumentListener(new DocumentListener() { @Override - public void mouseClicked(MouseEvent e) { + public void insertUpdate(DocumentEvent e) { + Document d = e.getDocument(); + try { + String text = d.getText(0, d.getLength()); + main.textEvent(key, text); + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } + } + @Override + public void removeUpdate(DocumentEvent e) { + Document d = e.getDocument(); + try { + String text = d.getText(0, d.getLength()); + main.textEvent(key, text); + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } } @Override - public void mousePressed(MouseEvent e) { - main.mouseEvent(key, 1); - } - @Override - public void mouseReleased(MouseEvent e) { - main.mouseEvent(key, 0); - } - @Override - public void mouseEntered(MouseEvent e) { - } - @Override - public void mouseExited(MouseEvent e) { + public void changedUpdate(DocumentEvent e) { + Document d = e.getDocument(); + try { + String text = d.getText(0, d.getLength()); + main.textEvent(key, text); + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } } }); } else if (type.equals("label")) {