The imports are okay, I just want to print out the result in the JTextArea in the second JFrame after the search button is clicked.
When I run this program, my whole JFrame panel shows a huge full screen button named 'search'.
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame {
private static final long serialVersionUID = 1L;
private static final String DB_PATH = "C:/Users/Abed/Documents/Neo4j/Movies2.graphdb";
public static GraphDatabaseService graphDB;
public static void main(String[] args) throws Exception {
showFrame();
}
public static void showFrame() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(500, 500);
final JTextField actorInput = new JTextField(10);
final JTextField genreInput = new JTextField(10);
frame.getContentPane().add(actorInput);
frame.getContentPane().add(genreInput);
JButton submit = new JButton("Search");
submit.setSize(5, 5);
frame.getContentPane().add(submit);
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
graphDB = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
Transaction tx = graphDB.beginTx();
String actor = actorInput.getText();
String genre = genreInput.getText();
final String query;
query = "MATCH (Movie {genre:'"
+ genre
+ "'})<-[:ACTS_IN]-(Person {name:'"
+ actor
+ "'}) "
+ "RETURN Person.name, Movie.genre, COUNT(Movie.title) AS cnt "
+ "ORDER BY cnt DESC " + "LIMIT 100 ";
try {
JFrame frame2 = new JFrame();
frame2.setVisible(true);
JTextArea ta = new JTextArea();
ta.setLineWrap(true);
frame2.add(ta);
ExecutionEngine engine = new ExecutionEngine(graphDB,
StringLogger.SYSTEM);
ExecutionResult result = engine.execute(query);
System.out.println(result);
String resultArea = result.dumpToString();
ta.setText(resultArea);
tx.success();
} finally {
tx.close();
graphDB.shutdown();
}
}
});
}
}