Note that there are some explanatory texts on larger screens.

plurals
  1. POJLabel with problems
    primarykey
    data
    text
    <p>I want to make a questionary in java. Here is my code:</p> <pre><code>import java.awt.*; import java.awt.Event.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class Chestionar extends JFrame { public Chestionar() { super("Chestionar"); final int x, y, z; x = y = z = 0; String ch1; JPanel jp = new JPanel(); JLabel jl = new JLabel("Name:"); JTextField jtf = new JTextField(10); ch1 = jtf.getText(); jp.add(jl); jp.add(jtf); add(jp); JPanel jp1 = new JPanel(); JLabel jl1 = new JLabel(); String s = "Welcome"; jl1.setText(s); jp1.add(jl1); add(jp1); //first question final JPanel jp2 = new JPanel(); JLabel jl2 = new JLabel("What is called as the roof of the world? 1.Nepal 2.Tibet etc"); final JComboBox jcb = new JComboBox(); for(int i=0; i&lt;5; i++){ jcb.addItem(i); } ActionListener alege = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if(jcb.getSelectedItem().toString().equals("2")){ JLabel bine = new JLabel("Right"); jp2.add(bine); } else { JLabel gresit = new JLabel("Wrong"); jp2.add(gresit); } } }; jcb.addActionListener(alege); jp2.setLayout(new FlowLayout()); jp2.add(jl2); jp2.add(jcb); add(jp2); setVisible(true); setLayout(new GridLayout(4, 1)); setSize(600, 600); } public static void main(String arg[]) { Chestionar ch = new Chestionar(); } } </code></pre> <p>I want to make to appear that JLabel with "right" or "wrong" that depends on the selected item from <code>JComboBox</code>. I don't know why, if a choose an item from <code>JComboBox</code> the specific <code>JLabel</code> doesn't appear, only if I re-size the main frame.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload