Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't start my applet program!
    primarykey
    data
    text
    <p>I have done some applet program in java, which will change the color of the text when button is been clicked, the coding is given below: </p> <pre><code> import java.awt.*; import java.applet.*; import java.awt.event.*; public class colorpalette extends Applet implements ActionListener { TextArea text; Button b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12; Panel p; public void init() { text = new TextArea(5, 10); b1 = new Button("lightgrey"); b2 = new Button("grey"); b3 = new Button("darkgrey"); b4 = new Button("black"); b5 = new Button("red"); b6 = new Button("pink"); b7 = new Button("orange"); b8 = new Button("yellow"); b9 = new Button("green"); b10 = new Button("magenta"); b11 = new Button("cyan"); b12 = new Button("blue"); p = new Panel(); p.setLayout(new GridLayout(4, 3)); p.add(b1); p.add(b2); p.add(b3); p.add(b4); p.add(b5); p.add(b6); p.add(b7); p.add(b8); p.add(b9); p.add(b10); p.add(b11); p.add(b12); setLayout(new BorderLayout()); add("North", p); add("South", text); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); b5.addActionListener(this); b6.addActionListener(this); b7.addActionListener(this); b8.addActionListener(this); b9.addActionListener(this); b10.addActionListener(this); b11.addActionListener(this); b12.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (e.getActionCommand() == "lightgrey") text.setBackground(Color.LIGHT_GRAY); else if (e.getActionCommand() == "grey") text.setBackground(Color.GRAY); else if (e.getActionCommand() == "darkgrey") text.setBackground(Color.DARK_GRAY); else if (e.getActionCommand() == "black") text.setBackground(Color.black); else if (e.getActionCommand() == "red") text.setBackground(Color.red); else if (e.getActionCommand() == "pink") text.setBackground(Color.pink); else if (e.getActionCommand() == "orange") text.setBackground(Color.orange); else if (e.getActionCommand() == "yellow") text.setBackground(Color.yellow); else if (e.getActionCommand() == "green") text.setBackground(Color.green); else if (e.getActionCommand() == "magenta") text.setBackground(Color.magenta); else if (e.getActionCommand() == "cyan") text.setBackground(Color.cyan); else if (e.getActionCommand() == "blue") text.setBackground(Color.blue); } } //&lt;applet code="colorpalette" width=50 height=50&gt; //&lt;\applet&gt; </code></pre> <p>Assume that this file name is colorpalette. And when I compile <code>javac colorpalette.java</code> there is no error, but when i run the program using <code>java colorpalette</code> I'm getting an error as <code>Exception in thread "main" java.lang.NoSuchMethodError: main</code>. </p> <p>Can anyone say me, where I went wrong!</p>
    singulars
    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.
    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