It compiles but my JButton won't work...
when i run the applet and press the Exit button.. it just prints some errors(or i dunno what they are) in the black window that opens when you run the applet.

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


public class CheckRadioTest extends JApplet implements ItemListener
{
    //private String CurrentComboName = "Select One";

    private JLabel headingLabel;
    private int currentStyle = Font.PLAIN; //private int intBold = Font.PLAIN; //private int intItalic = Font.PLAIN;
    private Color currentColor = Color.black;
    private JCheckBox cbBold , cbItalic ;
    private JRadioButton  rbRed , rbGreen , rbBlue; // mga Item... dili Action... ang button usa ra siya... Itemssssssssssssssssssssssss .. mao nang ItemEvent
    private ButtonGroup ColorSelectGroup;
    private String[] items = {"item1" , "item2" , "item3" , "item4"};
    private JComboBox myfirstcombobox = new JComboBox(items);
    private JButton buttonAppend,buttonExit;
    private EBHandler eHandler;

    public void init()
    {
        Container c = getContentPane();
        c.setLayout(null);

        cbBold = new JCheckBox("Bold");
        cbItalic = new JCheckBox("Italic");
        rbRed = new JRadioButton("Red");
        rbGreen = new JRadioButton("Green");
        rbBlue = new JRadioButton("Blue");
        headingLabel = new JLabel("select from combo box");




        //EXIT BUTTON
        buttonExit = new JButton("Exit");
        eHandler = new EBHandler();
        buttonExit.addActionListener(eHandler);

        cbBold.setSize(100,30);
        cbItalic.setSize(100,30);
        rbRed.setSize(100,10);
        rbGreen.setSize(100,10);
        rbBlue.setSize(100,10);
        myfirstcombobox.setSize(100,30);
        headingLabel.setSize(300,50);
        buttonExit.setSize(82,30);

        cbBold.setLocation(100,85);
        cbItalic.setLocation(100,125);
        rbRed.setLocation(310,60);
        rbGreen.setLocation(310,100);
        rbBlue.setLocation(310,150);
        myfirstcombobox.setLocation(20,10);
        headingLabel.setLocation(125,10);
        buttonExit.setLocation(320,200);



        cbBold.addItemListener(this);
        cbItalic.addItemListener(this);
        rbRed.addItemListener(this);
        rbGreen.addItemListener(this);
        rbBlue.addItemListener(this);
        myfirstcombobox.addItemListener(this);




        c.add(cbBold);
        c.add(cbItalic);
        c.add(rbRed);
        c.add(rbGreen);
        c.add(rbBlue);
        c.add(myfirstcombobox);
        c.add(headingLabel);
        c.add(buttonExit);

        ColorSelectGroup = new ButtonGroup();
        ColorSelectGroup.add(rbRed);
        ColorSelectGroup.add(rbGreen);
        ColorSelectGroup.add(rbBlue);

        //NameComboBox = new JComboBox(Name);
    }
        public void paint(Graphics g)
        {
            super.paint(g);
            g.setColor(Color.orange);
            g.drawRoundRect(75, 50 , 125 ,140 , 10 , 24); // x , y, width, length , height , thickness
            g.drawRoundRect(275 , 50 ,125 , 140 , 10 , 10);
            g.setColor(currentColor);
            g.setFont(new Font("Times New Roman", Font.PLAIN, 15));
            g.drawString("Drawn String" ,300, 30);


        }

    private class EBHandler implements ActionListener
    {   public void actionPerformed(ActionEvent ex)
        {
            System.exit(0);
        }
    }

    public void ActionPerformed (ActionEvent e)
    {
        if (e.getActionCommand().equals("Exit"))

        System.exit(0);

    }

    public void itemStateChanged (ItemEvent e)
    {

            if(e.getSource() == cbBold)
            {
                if(e.getStateChange() == ItemEvent.SELECTED)
                    currentStyle = Font.BOLD; //intBold = Font.BOLD;
                if(e.getStateChange() == ItemEvent.DESELECTED)
                    currentStyle = Font.PLAIN; //intBold = Font.PLAIN;

                    repaint();

            }
            if(e.getSource() == cbItalic)
            {
                if(e.getStateChange() == ItemEvent.SELECTED)
                    currentStyle = Font.ITALIC; //intItalic = Font.Italic;
                if(e.getStateChange() == ItemEvent.DESELECTED)
                    currentStyle = Font.PLAIN; //intItalic = Font.PLAIN;

                    repaint();

            }



            if(e.getSource() == rbRed)
                currentColor = Color.red;

            else if(e.getSource() == rbGreen)
                currentColor = Color.green;

            else if(e.getSource() == rbBlue)
                    currentColor = Color.blue;



             //if (e.getSource() == NameComboBox)
             //Current = Name [NameComboBox.index()];
        }




}

Recommended Answers

All 2 Replies

Applets are not allowed to use System.exit(0). The browser is in control. Use showDocument() if you want a different page shown or remove all the components that are being shown.

THANK YOU! ^_^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.