0

I just want to create a JComboBox. And, I paste the following code in https://www.compilejava.net/ and nothing is shown in the window. So, what's wrong with the code? Or does the online compiler have problems? If so, are there any online compiler that works?

import java.awt.*;
import javax.swing.*;
import java.awt.event.*; 

public class test{

private JFrame f; //window
private JPanel p; //layout


private JComboBox<String> j; //pull down menu

public static void main(String[] args){
   new test();
}

public test(){
   f = new JFrame("title of window");
   f.setVisible(true); 
   f.setSize(600,400);
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

   p = new JPanel();
   p.setBackground(Color.YELLOW);

   String[] bookTitles = new String[] {"Effective Java", "Head First Java",
                                "Thinking in Java", "Java for Dummies"};
   JComboBox<String> bookList = new JComboBox<>(bookTitles);
   p.add(bookList);

   f.add(p);
}

}
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Keroro Chan
  • 99
  • 1
  • 10

0 Answers0