fork download
  1. import java.awt.BorderLayout;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import javax.swing.*;
  5.  
  6. class DictionaryScreen extends JFrame {
  7. private JTextField searchField;
  8. private JTextArea displayArea;
  9.  
  10. public DictionaryScreen() {
  11. // Set up the window properties
  12. setTitle("Dictionary");
  13. setSize(400, 300);
  14. setLocationRelativeTo(null);
  15. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  16.  
  17. // Create the search bar and add a listener
  18. searchField = new JTextField();
  19. searchField.addActionListener(new ActionListener() {
  20. public void actionPerformed(ActionEvent e) {
  21. // Perform search here and display results in display area
  22. displayArea.setText("Definition of " + searchField.getText() + ": Lorem ipsum dolor sit amet, consectetur adipiscing elit.");
  23. }
  24. });
  25.  
  26. // Create the display area
  27. displayArea = new JTextArea();
  28. displayArea.setEditable(false);
  29.  
  30. // Add components to the window
  31. add(searchField, BorderLayout.NORTH);
  32. add(new JScrollPane(displayArea), BorderLayout.CENTER);
  33.  
  34. setVisible(true);
  35. }
  36.  
  37. public static void main(String[] args) {
  38. SwingUtilities.invokeLater(new Runnable() {
  39. public void run() {
  40. new DictionaryScreen();
  41. }
  42. });
  43. }
  44. }
Success #stdin #stdout #stderr 0.26s 63120KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "AWT-EventQueue-0" java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
	at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:197)
	at java.desktop/java.awt.Window.<init>(Window.java:538)
	at java.desktop/java.awt.Frame.<init>(Frame.java:423)
	at java.desktop/java.awt.Frame.<init>(Frame.java:388)
	at java.desktop/javax.swing.JFrame.<init>(JFrame.java:180)
	at DictionaryScreen.<init>(Main.java:10)
	at DictionaryScreen$2.run(Main.java:40)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)