How could i add actions to this program....

i am trying to add action events so that the menuItems will do something when selected (with if else statements) such as changing the background color or font text
yes, i am very new to java
thanks for any help
here is what i'm working with
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ThemeChanger extends JFrame
JTextArea output;
JScrollPane scrollPane;
public ThemeChanger()
JMenuBar menuBar;
JMenu menu;
JMenuItem blue;
JMenuItem red;
JMenuItem green;
addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
// Add components to window
Container contentPane = getContentPane();
output = new JTextArea(5, 20);
output.setEditable(false);
scrollPane = new JScrollPane(output);
contentPane.add(scrollPane, BorderLayout.CENTER);
//Create the menu bar.
menuBar = new JMenuBar();
setJMenuBar(menuBar);
//Build the first menu.
menu = new JMenu("Themes");
menuBar.add(menu);
//a group of JMenuItems
blue = new JMenuItem("Blue");
menu.add(blue);
red = new JMenuItem("Red");
menu.add(red);
green = new JMenuItem("Green");
menu.add(green);
public static void main(String args[])
ThemeChanger window = new ThemeChanger();
window.setTitle("Theme Changer");
window.setSize(300, 300);
window.setVisible(true);

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ThemeChanger extends JFrame implements ActionListener{
   JMenuItem blue;
   JMenuItem red;
   JMenuItem green;
   JMenuItem coorier = new JMenuItem("Courier");
   JMenuItem times = new JMenuItem("Times new Roman");
   JMenuItem tahomah = new JMenuItem("Tahoma");;
   JMenuItem comics = new JMenuItem("Verdana");;  
   JMenu mFont;
   JTextArea output;
   JComboBox fontSizes;
   boolean newFont;
   String fontChanged = "Arial";
   int mySize = 12;
   Font startFont = new Font(fontChanged, Font.PLAIN,mySize);
  public ThemeChanger(){
     JMenu menu;
     Container contentPane = getContentPane();
     output = new JTextArea(4, 12);
     output.setFont(startFont);
     JScrollPane scrollPane = new JScrollPane(output);
     contentPane.add(scrollPane, BorderLayout.CENTER);
     JMenuBar menuBar = new JMenuBar();
     setJMenuBar(menuBar);
     menu = new JMenu("Colour");
     menuBar.add(menu);
     blue = new JMenuItem("Blue");
     blue.addActionListener(this);
     menu.add(blue);
     red = new JMenuItem("Red");
     menu.add(red);
     red.addActionListener(this);
     green = new JMenuItem("Green");
     green.addActionListener(this);
     menu.add(green);
     mFont= new JMenu("Font");
      mFont.add(coorier);
      coorier.addActionListener(this);
      mFont.add(times);
      times.addActionListener(this);
      mFont.add(tahomah);
      tahomah.addActionListener(this);
      mFont.add(comics);
      comics.addActionListener(this);
      menuBar.add(mFont);
      mFont.addActionListener(this);
     fontSizes = new JComboBox();
      fontSizes.addItem("Size");
      fontSizes.addItem("8");
      fontSizes.addItem("10");
      fontSizes.addItem("11");
      fontSizes.addItem("12"); 
      fontSizes.addItem("14");
      fontSizes.addItem("18");
      fontSizes.addItem("22");
      fontSizes.addItem("28");
      fontSizes.addItem("36");
      fontSizes.addItem("48");
      fontSizes.addItem("72");
        fontSizes.setMaximumRowCount(5);
      fontSizes.setBackground(Color.white);
      fontSizes.addActionListener(this);
     menuBar.add(fontSizes);
  public void actionPerformed(ActionEvent e){
    if(e.getSource()==blue)  output.setForeground(Color.blue);
    if(e.getSource()==red)   output.setForeground(Color.red);
    if(e.getSource()==green) output.setForeground(Color.green);
    if(e.getSource()==fontSizes) {
       mySize = Integer.parseInt((String)fontSizes.getSelectedItem());
       output.setFont(new Font(fontChanged, Font.PLAIN,mySize));
    if(((e.getSource()==coorier))||((e.getSource()==times)||(e.getSource()==tahomah))||((e.getSource()==comics))) {
       fontChanged = e.getActionCommand();
       output.setFont(new Font(fontChanged, Font.PLAIN,mySize));
  public static void main(String args[]) {
     ThemeChanger window = new ThemeChanger();
     window.setTitle("Theme Changer");
     window.setSize(300, 300);
     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     window.setVisible(true);
}

Similar Messages

  • How could i add attachment in this code

    i have code when_button_pressed (send email) but i want attach file
    how can i do this ?
    this is the code
    -------only for outlook
    --- THIS IS OLE CODE FOR MORE INFO. SEE HELP .
    DECLARE
    --PROCEDURE SendMail
    objOutlook OLE2.OBJ_TYPE;
    objMail OLE2.OBJ_TYPE;
    objArg OLE2.LIST_TYPE;
    vfilename varchar2(300);
    BEGIN
    objOutlook := OLE2.CREATE_OBJ('OUTLOOK.Application');
    objarg := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(objarg,0);
    objMail := OLE2.INVOKE_OBJ(objOutlook,'CreateItem',objarg);
    OLE2.DESTROY_ARGLIST(objarg);
    OLE2.SET_PROPERTY(objmail,'To',:TO);
    OLE2.SET_PROPERTY(objmail,'Subject',:SUBJECT);
    OLE2.SET_PROPERTY(objmail,'Body',:BODY);
    OLE2.INVOKE(objmail,'Send');
    OLE2.INVOKE(objmail,'Display');
    OLE2.RELEASE_OBJ(objmail);
    OLE2.RELEASE_OBJ(objOutlook);
    Message('Your mail sent successfully..............');
    Message('Your mail sent successfully..............');
    exception
    when others then
    message(sqlerrm);message(sqlerrm);
    END;
    thanks.

    Hello,
    Try this:
    OLE2.SET_PROPERTY(objmail,'Attachments','c:\file.txt');Francois

  • Add statements to this program so that it computes the circumference....

    How do I add statements to this program so that it computes the circumference in addition to the area for both circles?
    // Circle.java
    // Print the area of a circle with two different radii
    import java.util.Scanner;
    public class circle{
    public static void main(String[] args){
    final double PI = 3.14159;
    int radius;
    Scanner scan = new Scanner(System.in);
    System.out.print ("Please enter the a radius ");
    radius = scan.nextInt();
    double area = PI * radius * radius;
    System.out.println("The area of a circle with radius " + radius +
    " is " + area);
    System.out.print ("Please enter the a radius ");
    radius = scan.nextInt();
    area = PI * radius * radius;
    System.out.println("The area of a circle with radius " + radius +
    " is " + area);
    }

    Did you write this code? If so, then you already know how to add statements to do more stuff, since that's what you did to write this in the first place.
    Do you know how to calculate circurmference?

  • How could I add a new pakage to JDK

    I want to import org.appache.fop.apps.*;(fop.jar) in my program, and how could I add these pakages to JDK.
    Thanks for help.

    Remember, when you upgrade JDK you will need to do the copy again. You may want to consider keeping your packages separate from JDK.
    Ron 8)

  • I have Photoshop CS4,on how many computers can you install this program ?

    Hello,
    I got Photoshop CS4. On how many computers can you install this program ?
    Sonste

    The license and activation rights are for a single user on two computers that are not used simultaneously—such as your desktop machine and your laptop.

  • Arabic is not listed as a display language in iTunes for Windows 7. How can I add support for this language?

    Arabic is not listed as a display language in iTunes for Windows 7. How can I add support for this language?

    Edit  ---> referance ----->   general    ------> language

  • How could I add a spanish voice from text-to-Speech?

    I like the text-to-speech function. But there is no Spanish Voice. How could I add  a Spanish voice to it? I use Captivate 5.5.
    Your reply will be greatly appreciated.

    Using iPhone, iPad, or iPod with multiple computers - http://support.apple.com/kb/HT1202 - You can manage your iPhone, iPad, or iPod with multiple computers as long as you have set the device to "Manually manage music."  -  E.g., adding music from a second computer to an i-device. Additional information about switching sync mode - https://discussions.apple.com/thread/4435531 and manually adding in iTunes 11 https://discussions.apple.com/thread/4597408

  • How could we add fields in web ui

    Hello Expert,
    Could  any body say that how could I add new field in Web UI... Please revert...
    Thanks
    Satish Lath

    Hi Satish,
    What Silpa has replied is the approach to bring an existing field into webui. If you have a requirement to add a new field then you can do it either through AET or EEWB.
    http://wiki.sdn.sap.com/wiki/display/CRM/EEWB-AddingTableattribute
    /people/vikash.krishna/blog/2009/07/14/crm-70-how-to--4-adding-custom-fields-with-the-new-application-enhancement-tool-aet
    Follow the above blogs to know more about EEWB and AET.
    Thanks,
    Raman

  • I have a huge amount of my memory used by 'other' than photos and music - to my knowledge, there is nothing there apart from a few songs and photos and 5 podcasts. What could it be? How could I get rid of this 'other' stuff and get the memory back?

    I have a huge amount of my memory used by 'other' than photos and music - to my knowledge, there is nothing there apart from a few songs and photos and 5 podcasts. What could it be? How could I get rid of this 'other' stuff and get the memory back?

    See -> What is "Other" and what can I do about it? by Kappy.
    Clinton

  • Is it possible to add additional features, such as I had in iTunes? What I mean is: how could I add comments for example of an ebook; or the publisher?

    Is it possible to add additional features, such as I had in iTunes? What I mean is: how could I add comments for example of an ebook; or the publisher?

    Many thanks Brett, but probably I wasn't clear enough about my problem.
    I know that I'm able to include some notes, or to highlight paragraph; what I want to know if is it possible to make a summary of the book; or add additional features such as Publisher, if I read or not; language, etc. And show in the information for each book … In the application there's only: title, author, genre … How can add additional features as a reference for the ebook as a whole, and see them at the same level of the author, genre, etc.
    For example
    BOOK A          AUTHOR BRETT L     PHILOSOPHY     ENGLISH     TO READ     iTUNES STORE    
    The first three items are the default items … what I want to include is the others (as an example) … And create a box or something to make a summary of the book.
    Sorry for the bothering … but I was (and I suppose I'm not the only one) very comfortable with iTunes format for Music; but iBooks lost quite everything compared to iTunes; and it looks like a mere Kindle application.
    Many thanks in advance
    Gerardo Garcia Gorostidi

  • I need help, How could I add Aliases to Local Administrator account via terminal commands???

    I need help, How could I add Aliases to Local Administrator account via terminal commands???
    I want to use commands to add alias for existing administrator account remotly by using ARD.
    Thanks.

    Hi,
    a Windows Domain Controller does not have any local user or groups. So you might add the user to the admin group at Domain level.
    B RGDS,
    Gregor
    Edited by: Gregor Gasper on Jan 9, 2009 1:44 PM

  • Creative Cloud: How many computers can I download this program to?

    I bought the 119 subscription and I have yet to use it because I am waiting on my new laptop. How many computers can I download this program to??

    OK having issues. I signed into my account on adobe on my new computer but
    after signing in I can't download the program it says download trial
        Creative Cloud: How many computers can I download this program to?
    created by John Waller <https://forums.adobe.com/people/John+Waller> in *Adobe
    Creative Cloud* - View the full discussion
    <https://forums.adobe.com/message/7264004#7264004>

  • Stupid ios 6 .... How apple will take action on this. I want to trow my iphone now!!!

    Stupid ios 6 ...How apple will take action on this. I want to trow my iphone now

    Go ahead, but be careful it doesn't hit any innocent people.

  • How can I add action listener to a cell or row in a table?

    hi there
    I need to be able to click on one cell or one row in a table, and perform some action, like openning a dialog or something. how can i add listener?

    // See How to Use Tables in tutorial. You will get one idea about Table Renderer and Editors.
    // If u understand the concept, ur problem is very easy to solve by adding Editor to your column.
    "You can think of the renderer as a configurable ink stamp that the table uses to stamp appropriately formatted data onto each cell. When the user starts to edit a cell's data, a cell editor takes over the cell, controlling the cell's editing behavior.
    Here, While tabing thru the table row, default all cell editors are JLabels. (Not editables)
    So u can make it those cells are editable JTextFields or JComboBoxes based on the column while tabbing. And you can add Listeners to that fields too. So those editable fields are called Editor Components.
    // see javax.swing.DefaultCellEditor class for more description
    Here i am adding my own JTextField editor to 3rd column of a table by using
    mytable.getColumnModel().getColumn(2).setCellEditor(editor );
    Here editor is a obj of below class. (Not complete..class)
    public class JbuiEditor extends DefaultCellEditor implements // any listener {
    public JbuiEditor(JTextField tField) {
    super(tField);
    setClickCountToStart(1);
    tField.addFocusListener(this);
    this.editorComponent = tField;
    public Component getComponent(){
         return editorComponent;
    public Component getTreeCellEditorComponent(JTree tree, Object value,
                                  boolean isSelected,
                                  boolean expanded,
                                  boolean leaf, int row) {
         String StringValue = tree.convertValueToText(value, isSelected,
                             expanded, leaf, row, false);
         delegate.setValue(stringValue);
         return editorComponent;
    public Object getCellEditorValue() {
    return super.getCellEditorValue();
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,int row, int column) {
    super.getTableCellEditorComponent(table,value,isSelected,row,column);
    ((JTextField)editorComponent).setText(value.toString());
    //Here u can add any type of listener to this Editor component.like..
    ((JTextField)editorComponent).addActionListener(..);
    ((JTextField)editorComponent).addFocusListener(..);
    return editorComponent;
    Hope gives some idea.

  • How could I ADD ITEM by using API

    Hi,
    I have Portal 9.0.3 installed.
    I want to call wwsbr_api from a javascript code (HTML portlet) to add a text item to a region, but I have some problem using this API:
    1; I don't know how could I get the p_caid, the p_folder_id and the region_id
    I found out that p_caid can be find WWSBR_SITES.ID. Is this correct?
    2; when I've tried to call this API from address line I've got a 404 ERROR (but it might have been casued by the wrong attribute values)
    So I need to know:
    - How could I find out the correct IDs?
    - How could I call wwsbr_api.add_item function from a javascript?
    Thanks for your help!
    THE BOOGIE IS OVER

    WWSBR_API is currently not supported in Portal Release 2 (902). Support for this API will return in the next version (9.0.2.6, planned for early 2003).
    Regards,
    Portal Product Manager

Maybe you are looking for

  • Configuration of standard server, 10.5.4 install disk, small office, DNS

    I've reinstalled more times than I care to count. Been on the phone with support people- no one seems to know how to install standard in my config. I have a fixed business class IP- it connects from their modem to my Apple Extreme basestation N gigab

  • Dynamically deleting row in struts

    Hi All, Can any one suggest me how to delete a row by highlighting it. I am using struts frame work and my home page consists of a table with the data populated from the database, my requirement here is to give an option to the user to delete a row b

  • Mouse flickering

    My mousecursor is flickering when i go over a canvas3D. Can i solve this problem? thanx

  • Self registration, problem

    Hi experts, I'm traiying to implement self regitration with company approval, I'm using EP 7.0 SP 10, I have configured two Frameworks (Anonymous, Authenticated) and are working fine, I have followed instructions found on http://help.sap.com to confi

  • Colour differences in Photoshop CS4 and Flash CS4 - help!

    Hi, I've been having problems for a while now when working with Photoshop and Flash, so now I will try to find an answer to my problem. The thing is, when I try to take designs from Photoshop to Flash, the colours are changing/looking wrong. See my a