Hallo,
ich habe eine kleine GUI geschrieben. Jetzt bin ich aber gerade ein wenig am Rätseln.
Ich würde gerne beim drücken des Knopfes "Run" die GUI schließen.
[HIGHLIGHT="Java"]import gov.nih.nlm.kss.api.KSSRetrieverV5_0;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import org.w3c.dom.Document;
import rmi.RMIClient;
import rmi.XMLBaseGenerator;
public class UMLS_Test extends JFrame{
private String language="ENG";
private String manipType="Word";
private String method="getCUI";
private String sources="standard";
private String term="";
private String[] langOptions = { "ENG", "GER" };
private String[] manipOptions = { "Word", "NormalizeString","NormalizeWord","ExactMatch","TruncateRight","TruncateLeft","ApproxMatch" };
private String[] methodOptions = { "getCUI", "getConcept" };
private String[] vectorOptions = { "standard", "all" };
private JLabel termLabel = new JLabel("Term");
private JLabel langLabel = new JLabel("Lanuage");
private JLabel manipLabel = new JLabel("ManipType");
private JLabel methodLabel = new JLabel("Method");
private JLabel vectorLabel = new JLabel("Source") ;
private JTextField termField = new JTextField(35);
private JComboBox langBox = new JComboBox();
private JComboBox manipBox = new JComboBox();
private JComboBox methodBox = new JComboBox();
private JComboBox vectorBox = new JComboBox();
public UMLS_Test(String name){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle(name);
this.setSize(520, 130);
Container inhalt = this.getContentPane();
JTable oberEbene = new JTable();
oberEbene.setLayout(new FlowLayout());
inhalt.add(oberEbene);
JPanel ersteEbene = new JPanel(new GridLayout(2,4));
oberEbene.add(ersteEbene);
JButton Runbutton = new JButton("Run");
oberEbene.add(termLabel);
oberEbene.add(termField);
oberEbene.add(Runbutton);
ersteEbene.add(langLabel);
ersteEbene.add(manipLabel);
ersteEbene.add(methodLabel);
ersteEbene.add(vectorLabel);
// Sprach Optionen:
for (int i = 0; i < 2; i++){
this.langBox.addItem(langOptions);}
ersteEbene.add(langBox);
langBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
language=(String) ((JComboBox) e.getSource()).getSelectedItem();
}
});
// ManipType Optionen:
for (int j = 0; j < 7; j++){
this.manipBox.addItem(manipOptions[j]);}
ersteEbene.add(manipBox);
manipBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
manipType=(String) ((JComboBox) e.getSource()).getSelectedItem();
}
});
//Method Optionen:
for (int k = 0; k < 2; k++){
this.methodBox.addItem(methodOptions[k]);}
ersteEbene.add(methodBox);
methodBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
method=(String) ((JComboBox) e.getSource()).getSelectedItem();
}
});
//Vector Optionen:
for (int l = 0; l < 2; l++){
this.vectorBox.addItem(vectorOptions[l]);}
ersteEbene.add(vectorBox);
vectorBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sources=(String) ((JComboBox) e.getSource()).getSelectedItem();
}
});
termField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
term=(String) ((JTextField) e.getSource()).getText();
System.out.println("Search Term: \""+term+"\"");
}
});
Runbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Run Method \""+ method+"\" in language \""+language+"\" with manipType set to \""+manipType+"\" and with usage of "+sources+ " sources.");
}
});
// display the GUI
this.setVisible(true);
}
public static void main(String[] args) {
UMLS_Test gui = new UMLS_Test("LRSMed-Tester");
//String search_fulltext = "ACUTE PULMONARY HEART DISEASE NOS"; //sollte klappen
//String search_fulltext ="ACUTE RHEUMATIC HEART DISEASE";
//String search_fulltext = "Heart";
//String language = "ENG"; // oder GER... vom Formular kommt hier eine
//Vector vecSabs = null;
//XMLBaseGenerator xmlParser= null;
/* 1(GER) oder 2(ENG)
// Wenn Sprache englisch oder Deutsch werden mit "getSabsVectorDe", oder
// "getSabsVectorEn" folgende Vectoren angelegt:
// Also die Vectoren werden mit den jeweils 10 aktuellen Quellabkürzungen
gefüllt.*/
//Vector sabsDe = new Vector();
//Vector sabsEn = new Vector();
// jeweils 10 Werte noch einfügen => TODO: mal in umls_data.xml nachsehen
//sabsDe.add("MSHGER");
//sabsEn.add("MSH");
//sabsEn.add("WHO");
//sabsEn.add("");
// Wenn der Vector ganz leer ist => Endlosschleife
// hier wird dann wenn Englisch der englische vector genommen bzw deutsche
// vecSabs= sabsEn; // das is jetzt der englische vector einfach.
/* DOM = Document Object Model=>
* Den Document teil verstehe ich noch nicht.
* */
//RMIClient c= new RMIClient();
//c.connectedUmlsks();
//String result=c.findConcept( search_fulltext, vecSabs, language ,KSSRetrieverV5_0.NormalizeWord);
//String result=c.findCUI( search_fulltext, vecSabs, language ,KSSRetrieverV5_0.Word);//TruncateRight,ExactMatch
//String result=c.getContext(search_fulltext);
// c.disconnectedUmlsks();
//System.out.println(result);
}
}[/HIGHLIGHT]
Desweiteren würde ich gerne mit dem Actionlistener den Text aus dem JField (termField) direkt übernehmen.
Momentan ist es so, dass man den Text eintippen muss, dann enter drückt und erst dann wird der String term aktualisiert. Schöner fänd ichs wenn man kein enter drücken müsste. Aber ist nur ein testmodul für mich selber, also egal, allerdings, das mit dem close button fände ich schon gut, weiß jemand was man da genau anzustellen hat?
ich habe eine kleine GUI geschrieben. Jetzt bin ich aber gerade ein wenig am Rätseln.
Ich würde gerne beim drücken des Knopfes "Run" die GUI schließen.
[HIGHLIGHT="Java"]import gov.nih.nlm.kss.api.KSSRetrieverV5_0;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import org.w3c.dom.Document;
import rmi.RMIClient;
import rmi.XMLBaseGenerator;
public class UMLS_Test extends JFrame{
private String language="ENG";
private String manipType="Word";
private String method="getCUI";
private String sources="standard";
private String term="";
private String[] langOptions = { "ENG", "GER" };
private String[] manipOptions = { "Word", "NormalizeString","NormalizeWord","ExactMatch","TruncateRight","TruncateLeft","ApproxMatch" };
private String[] methodOptions = { "getCUI", "getConcept" };
private String[] vectorOptions = { "standard", "all" };
private JLabel termLabel = new JLabel("Term");
private JLabel langLabel = new JLabel("Lanuage");
private JLabel manipLabel = new JLabel("ManipType");
private JLabel methodLabel = new JLabel("Method");
private JLabel vectorLabel = new JLabel("Source") ;
private JTextField termField = new JTextField(35);
private JComboBox langBox = new JComboBox();
private JComboBox manipBox = new JComboBox();
private JComboBox methodBox = new JComboBox();
private JComboBox vectorBox = new JComboBox();
public UMLS_Test(String name){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle(name);
this.setSize(520, 130);
Container inhalt = this.getContentPane();
JTable oberEbene = new JTable();
oberEbene.setLayout(new FlowLayout());
inhalt.add(oberEbene);
JPanel ersteEbene = new JPanel(new GridLayout(2,4));
oberEbene.add(ersteEbene);
JButton Runbutton = new JButton("Run");
oberEbene.add(termLabel);
oberEbene.add(termField);
oberEbene.add(Runbutton);
ersteEbene.add(langLabel);
ersteEbene.add(manipLabel);
ersteEbene.add(methodLabel);
ersteEbene.add(vectorLabel);
// Sprach Optionen:
for (int i = 0; i < 2; i++){
this.langBox.addItem(langOptions);}
ersteEbene.add(langBox);
langBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
language=(String) ((JComboBox) e.getSource()).getSelectedItem();
}
});
// ManipType Optionen:
for (int j = 0; j < 7; j++){
this.manipBox.addItem(manipOptions[j]);}
ersteEbene.add(manipBox);
manipBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
manipType=(String) ((JComboBox) e.getSource()).getSelectedItem();
}
});
//Method Optionen:
for (int k = 0; k < 2; k++){
this.methodBox.addItem(methodOptions[k]);}
ersteEbene.add(methodBox);
methodBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
method=(String) ((JComboBox) e.getSource()).getSelectedItem();
}
});
//Vector Optionen:
for (int l = 0; l < 2; l++){
this.vectorBox.addItem(vectorOptions[l]);}
ersteEbene.add(vectorBox);
vectorBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sources=(String) ((JComboBox) e.getSource()).getSelectedItem();
}
});
termField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
term=(String) ((JTextField) e.getSource()).getText();
System.out.println("Search Term: \""+term+"\"");
}
});
Runbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Run Method \""+ method+"\" in language \""+language+"\" with manipType set to \""+manipType+"\" and with usage of "+sources+ " sources.");
}
});
// display the GUI
this.setVisible(true);
}
public static void main(String[] args) {
UMLS_Test gui = new UMLS_Test("LRSMed-Tester");
//String search_fulltext = "ACUTE PULMONARY HEART DISEASE NOS"; //sollte klappen
//String search_fulltext ="ACUTE RHEUMATIC HEART DISEASE";
//String search_fulltext = "Heart";
//String language = "ENG"; // oder GER... vom Formular kommt hier eine
//Vector vecSabs = null;
//XMLBaseGenerator xmlParser= null;
/* 1(GER) oder 2(ENG)
// Wenn Sprache englisch oder Deutsch werden mit "getSabsVectorDe", oder
// "getSabsVectorEn" folgende Vectoren angelegt:
// Also die Vectoren werden mit den jeweils 10 aktuellen Quellabkürzungen
gefüllt.*/
//Vector sabsDe = new Vector();
//Vector sabsEn = new Vector();
// jeweils 10 Werte noch einfügen => TODO: mal in umls_data.xml nachsehen
//sabsDe.add("MSHGER");
//sabsEn.add("MSH");
//sabsEn.add("WHO");
//sabsEn.add("");
// Wenn der Vector ganz leer ist => Endlosschleife
// hier wird dann wenn Englisch der englische vector genommen bzw deutsche
// vecSabs= sabsEn; // das is jetzt der englische vector einfach.
/* DOM = Document Object Model=>
* Den Document teil verstehe ich noch nicht.
* */
//RMIClient c= new RMIClient();
//c.connectedUmlsks();
//String result=c.findConcept( search_fulltext, vecSabs, language ,KSSRetrieverV5_0.NormalizeWord);
//String result=c.findCUI( search_fulltext, vecSabs, language ,KSSRetrieverV5_0.Word);//TruncateRight,ExactMatch
//String result=c.getContext(search_fulltext);
// c.disconnectedUmlsks();
//System.out.println(result);
}
}[/HIGHLIGHT]
Desweiteren würde ich gerne mit dem Actionlistener den Text aus dem JField (termField) direkt übernehmen.
Momentan ist es so, dass man den Text eintippen muss, dann enter drückt und erst dann wird der String term aktualisiert. Schöner fänd ichs wenn man kein enter drücken müsste. Aber ist nur ein testmodul für mich selber, also egal, allerdings, das mit dem close button fände ich schon gut, weiß jemand was man da genau anzustellen hat?
Zuletzt bearbeitet von einem Moderator: