Hi
I only give one condition switch case...
but it is showing error how can i solve this in a manner...
i want to add two actions how is it possible...
Would anybody please help me ...
import javax.swing.*;
import javax.swing.JButton;
import java.awt.*;
import java.awt.Font;
import java.awt.event.*;
public class bold
{
static JTextArea textarea;
static JFrame frame;
static JPanel panel;
static JButton bold;
//static JButton boldcancel;
public static void main(String args[])
{
frame = new JFrame("Textarea bold");
textarea = new JTextArea(15,35);
bold = new JButton("Bold");
//boldcancel = new JButton("Cancel Bold");
panel = new JPanel();
panel.add(textarea);
panel.add(bold);
//panel.add(boldcancel);
boldlistener blisten = new boldlistener();
bold.addActionListener(blisten);
//boldcancellistener bclisten = new boldcancellistener();
//bold.addActionListener(bclisten);
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(3);
frame.setSize(500,300);
frame.setVisible(true);
}
static class boldlistener implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
Object obj = evt.getSource();
switch(obj == bold) //switch
{
case obj :
Font font=new Font("Courier",Font.BOLD,14);
textarea.setFont(font);
break;
}
}
}
/*static class boldcancellistener implements ActionListener
{
public void actionPerformed(ActionEvent evtplain)
{
Object obj1 = evtplain.getSource();
if(obj1 == bold)
{
Font font=new Font("Courier",Font.PLAIN,14); //Font.BOLD,ITALIC
textarea.setFont(font);
}
}
}*/
}