Project - need help

Hello everyone, I am completely new to Java and am currently taking a beginner class. My instructor encouraged us to get on the forums for help so that's what I'm doing. My overall goal of the started project below is to have the user select one of the options and have a message dispaly (either a label box or a message box - doesnt matter) that states the corresponding Grade they would receive in the class. He's a huge Chiefs fan, that's why I'm doing it like this - for brownie points. I really am 100% new to all of this, any help would be greatly appreciated. I really really want all the lbls to be on one line and all the visibility to be set to false until they check one of them and the visibility comes up true until they check a diff one, etc...
Here's what I've got so far:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ListenApplet extends Applet implements ItemListener
     //Declare components
     CheckboxGroup cGrades = new CheckboxGroup();
     Checkbox optRock = new Checkbox("Chiefs Rock!", cGrades, false);
     Checkbox optGood = new Checkbox("Chiefs are Good!", cGrades, false);
     Checkbox optMaybe = new Checkbox("Chiefs Might Win!", cGrades, false);
     Checkbox optChance = new Checkbox("Chiefs Don't Have a Chance!", cGrades, false);
     Checkbox optSuck = new Checkbox("Chiefs Suck!", cGrades, false);
     Checkbox chkBold = new Checkbox("Bold");
     Font fntBold = new Font("Times New Roman", Font.BOLD, 12);
     Font fntPlain = new Font("Times New Roman", Font.PLAIN, 12);
     Label lblFontStyle = new Label("THE CHIEFS QUIZ");
     Label lblGradeA = new Label("You get an A!");
     Label lblGradeB = new Label("You get a B!");
     Label lblGradeC = new Label("You get a C!");
     Label lblGradeD = new Label("You get a D!");
     Label lblGradeF = new Label("You get an F!");
     public void init()
          //Add controls
          setBackground(Color.orange);
          Panel pnlChoices = new Panel();
          pnlChoices.setLayout(new GridLayout(20,0));
          pnlChoices.add(lblFontStyle);
          pnlChoices.add(chkBold);
          pnlChoices.add(lblGradeA);
          pnlChoices.add(lblGradeB);
          pnlChoices.add(lblGradeC);
          pnlChoices.add(lblGradeD);
          pnlChoices.add(lblGradeF);
          pnlChoices.add(new Label("Choose Wisely "));
          pnlChoices.add(optRock);
          pnlChoices.add(optGood);
          pnlChoices.add(optMaybe);
          pnlChoices.add(optChance);
          pnlChoices.add(optSuck);
          add(pnlChoices);
          chkBold.addItemListener(this);
          optRock.addItemListener(this);
          optGood.addItemListener(this);
          optMaybe.addItemListener(this);
          optSuck.addItemListener(this);
     public void itemStateChanged(ItemEvent item)
          //A check box or option button changed state. Check to see which
          //item changed and take action.
          //Get the object that caused the event
          Object eventSource = item.getSource();
          //Test for the Bold check box
          if (eventSource == chkBold)
               if (chkBold.getState())
               lblFontStyle.setFont(fntBold);
               else
               lblFontStyle.setFont(fntPlain);
}

There are a couple of options here:
1) You can call setVisible(false) to hide the labels. However, that may have an effect on the layout of the container.
2) Use a card layout and put in the label AND a blank component, and swap between them
3) Make a subclass of JLabel. Override paintComponent, such that, if it should be displayed, it calls super.paintComponent. Otherwise, it just returns.
(My preference is the third option).
- Adam

Similar Messages

  • A Menu Applet Project (need help)

    The Dinner Menu Applet
    I would need help with those codes ...
    I have to write a Java applet that allows the user to make certain choices from a number of options and allows the user to pick three dinner menu items from a choice of three different groups, choosing only one item from each group. The total will change as each selection is made.
    Please send help at [email protected] (see the codes of the project at the end of that file... Have a look and help me!
    INSTRUCTIONS
    Design the menu program to include three soups, three
    entrees, and three desserts. The user should be informed to
    choose only one item from each group.
    Use the following information to create your project.
    Clam Chowder 2.79
    Vegetable soup 2.99
    Peppered Chicken Broth 2.49
    Chicken 12.79
    Fish 10.99
    Beef 14.99
    Vanilla Ice Cream 2.79
    Rice Pudding 2.99
    Cheesecake 4.29
    The user shouldn�t be able to choose more than one item
    from the same group. The item prices shouldn�t be visible to
    the user.
    When the user makes his or her first choice, the running
    total at the bottom of the applet should show the price of
    that item. As each additional item is selected, the running
    total should change to reflect the new total cost.
    The dinner menu should be 200 pixels wide �� 440 pixels
    high and be centered on the browser screen. The browser
    window should be titled �The Menu Program.�
    Use 28-point, regular face Arial for the title �Dinner Menu.�
    Use 16-point, bold face Arial for the dinner menu group titles
    and the total at the bottom of the applet. Use 14-point regular
    face Arial for individual menu items and their prices. If you
    do not have Arial, you may substitute any other sans-serif
    font in its place. Use Labels for the instructions.
    The checkbox objects will use the system default font.
    Note: Due to complexities in the way that Java handles
    numbers and rounding, your price may display more than
    two digits after the decimal point. Since most users are used
    to seeing prices displayed in dollars and cents, you�ll need to
    display the correct value.
    For this project, treat the item prices as integers. For example,
    enter the price of cheesecake as 429 instead of 4.29. That
    way, you�ll get an integer number as a result of the addition.
    Then, you�ll need to establish two new variables in place of
    the Total variable. Run the program using integers for the
    prices, instead of float variables with decimals.
    You�ll have the program perform two mathematical functions
    to get the value for the dollars and cents variables. First,
    divide the total price variable by 100. This will return a
    whole value, without the remainder. Then get the mod of the
    number versus 100, and assign this to the cents variable.
    Finally, to display the results, write the following code:
    System.out.println("Dinner Price is $ " + dollars +"." + cents);
    Please send code in notepad or wordpad to [email protected]
    Here are the expectations:
    HTML properly coded
    Java source and properly compiled class file included
    Screen layout as specified
    All menu items properly coded
    Total calculates correctly
    * MenuApplet.java
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    * @author Rulx Narcisse
         E-mail address: [email protected]
    public class MenuApplet extends java.applet.Applet implements ItemListener{
    //Variables that hold item price:
    int clamChowderPrice= 279;
    int vegetableSoupPrice= 299;
    int pepperedChickenBrothPrice= 249;
    int chickenPrice= 1279;
    int fishPrice= 1099;
    int beefPrice= 1499;
    int vanillaIceCreamPrice= 279;
    int ricePuddingPrice= 299;
    int cheeseCakePrice =429;
    int dollars;
    int cents=dollars % 100;
    //cents will hold the modulus from dollars
    Label entete=new Label("Diner Menu");
    Label intro=new Label("Please select one item from each category");
    Label intro2=new Label("your total will be displayed below");
    Label soupsTrait=new Label("Soups---------------------------");
    Label entreesTrait=new Label("Entrees---------------------------");
    Label dessertsTrait=new Label("Desserts---------------------------");
      *When the user makes his or her first choice, the running
         total (i.e. dollars) at the bottom of the applet should show the price of
         that item. As each additional item is selected, the running
         total should change to reflect the new total cost.
    Label theDinnerPriceIs=new Label("Dinner Price is $ "+dollars +"."+cents);
      *Crating face, using 28-point, regular face Arial for the title �Dinner Menu.�
         Using 16-point, bold face Arial for the dinner menu group titles
         and the total at the bottom of the applet & using 14-point regular
         face Arial for individual menu items and their prices.
    Font bigFont = new Font ("Arial", Font.PLAIN,28);
    Font bigFont2 = new Font ("Arial", Font.BOLD,16);
    Font itemFont = new Font ("Arial", Font.PLAIN,14);
    //Here are the radiobutton on the applet...
    CheckboxGroup soupsG = new CheckboxGroup();
        Checkbox cb1Soups = new Checkbox("Clam Chowder", soupsG, false);
        Checkbox cb2Soups = new Checkbox("Vegetable Soup", soupsG, true);
        Checkbox cb3Soups = new Checkbox("Peppered Chicken Broth", soupsG, false);
    CheckboxGroup entreesG = new CheckboxGroup();
        Checkbox cb1Entrees= new Checkbox("Chicken", entreesG, false);
        Checkbox cb2Entrees = new Checkbox("Fish", entreesG, true);
        Checkbox cb3Entrees = new Checkbox("Beef", entreesG, false);
    CheckboxGroup dessertsG = new CheckboxGroup();
        Checkbox cb1Desserts= new Checkbox("Vanilla Ice Cream", dessertsG, false);
        Checkbox cb2Desserts = new Checkbox("Pudding Rice", dessertsG, true);
        Checkbox cb3Desserts = new Checkbox("Cheese Cake", dessertsG, false);
        public void init() {
            entete.setFont(bigFont);
            add(entete);
            intro.setFont(itemFont);
            add(intro);
            intro2.setFont(itemFont);
            add(intro2);
            soupsTrait.setFont(bigFont2);
            add(soupsTrait);
            cb1Soups.setFont(itemFont);cb2Soups.setFont(itemFont);cb3Soups.setFont(itemFont);
            add(cb1Soups); add(cb2Soups); add(cb3Soups);
            cb1Soups.addItemListener(this);cb2Soups.addItemListener(this);cb2Soups.addItemListener(this);
            entreesTrait.setFont(bigFont2);
            add(entreesTrait);
            cb1Entrees.setFont(itemFont);cb2Entrees.setFont(itemFont);cb3Entrees.setFont(itemFont);
            add(cb1Entrees); add(cb2Entrees); add(cb3Entrees);
            cb1Entrees.addItemListener(this);cb2Entrees.addItemListener(this);cb2Entrees.addItemListener(this);
            dessertsTrait.setFont(bigFont2);
            add(dessertsTrait);
            cb1Desserts.setFont(itemFont);cb2Desserts.setFont(itemFont);cb3Desserts.setFont(itemFont);
            add(cb1Desserts); add(cb2Desserts); add(cb3Desserts);
            cb1Desserts.addItemListener(this);cb2Desserts.addItemListener(this);cb2Desserts.addItemListener(this);
            theDinnerPriceIs.setFont(bigFont2);
            add(theDinnerPriceIs);
           public void itemStateChanged(ItemEvent check)
               Checkbox soupsSelection=soupsG.getSelectedCheckbox();
               if(soupsSelection==cb1Soups)
                   dollars +=clamChowderPrice;
               if(soupsSelection==cb2Soups)
                   dollars +=vegetableSoupPrice;
               else
                   cb3Soups.setState(true);
               Checkbox entreesSelection=entreesG.getSelectedCheckbox();
               if(entreesSelection==cb1Entrees)
                   dollars +=chickenPrice;
               if(entreesSelection==cb2Entrees)
                   dollars +=fishPrice;
               else
                   cb3Entrees.setState(true);
               Checkbox dessertsSelection=dessertsG.getSelectedCheckbox();
               if(dessertsSelection==cb1Desserts)
                   dollars +=vanillaIceCreamPrice;
               if(dessertsSelection==cb2Desserts)
                   dollars +=ricePuddingPrice;
               else
                   cb3Desserts.setState(true);
                repaint();
        }

    The specific problem is that when I load he applet, the radio buttons do not work properly and any calculation is made.OK.
    I had a look at the soup radio buttons. I guess the others are similar.
    (a) First, a typo.
    cb1Soups.addItemListener(this);cb2Soups.addItemListener(this);cb2Soups.addItemListener(this);That last one should be "cb3Soups.addItemListener(this)". The peppered chicken broth was never responding to a click. It might be a good idea to write methods that remove such duplicated code.
    (b) Now down where you respond to user click you have:
    Checkbox soupsSelection=soupsG.getSelectedCheckbox();
    if(soupsSelection==cb1Soups)
        dollars +=clamChowderPrice;
    if(soupsSelection==cb2Soups)
        dollars +=vegetableSoupPrice;
    else
        cb3Soups.setState(true);What is that last bit all about? And why aren't they charged for the broth? Perhaps it should be:
    Checkbox soupsSelection=soupsG.getSelectedCheckbox();
    if(soupsSelection==cb1Soups) {
        dollars +=clamChowderPrice;
    } else if(soupsSelection==cb2Soups) {
        dollars +=vegetableSoupPrice;
    } else if(soupsSelection==cb3Soups) {
        dollars +=pepperedChickenBrothPrice;
    }Now dollars (the meal price in cents) will have the price of the soup added to it every time.
    (c) It's not enough to just calculate dollars, you also have to display it to the user. Up near the start of your code you have
    Label theDinnerPriceIs=new Label("Dinner Price is $ "+dollars +"."+cents);It's important to realise that theDinnerPriceIs will not automatically update itself to reflect changes in the dollars and cents variables. You have to do this yourself. One way would be to use the Label setText() method at the end of the itemStateChanged() method.
    (d) Finally, the way you have written itemStateChanged() you are continually adding things to dollars. Don't forget to make dollars zero at the start of this method otherwise the price will go on and on accumulating which is not what you intend.
    A general point: If you have any say in it use Swing (JApplet) rather than AWT. And remember that both Swing and AWT have forums of their own which may be where you get the best help for layout problems.

  • Project -  need help rather quickly

    I am doing a 2 minute/ish long small project which will involve images flowing across the screen......with text which appears over them. Thats it taken down to basics.
    http://www.coremelt.com/products/products-for-final-cut-studio/imageflow-demo-re el.html
    is pretty much the effect i want to go for, but i am wondering if i can do those type of effects in FCP (i have about 3 weeks) without that plugin?
    If so can someone post some type of tutorials, to help a novice out.
    If not....i suppose i will need to buy the plugins in the video for £50.
    thanks

    Do you have only Final Cut Pro, or also Motion? This sort of animation can be done in either. But if you're not that familiar with the methods to set up the animations and managing all the tracks/objects involved it would certainly take a lot less time to use a canned animation tool like the one you linked to. It depends on whether you're getting paid to do this, I would imagine!

  • Student Project - Need Help With ViewPlatform Rotation

    Hello folks,
    I'm a student in Strathclyde University, Glasgow, and I'm currently doing a small project for one of my programming classes. I'm doing a 3D knots and crosses game but I'm having tremendous difficulty getting the rotation to work just the way I want it to. Let me decribe what I need.
    Visualise 27 cubes, arranged in a 3 x 3 x 3 structure, space out slightly: a 3D knots and crosses setup. I'm trying to get the ViewPlatform to rotate around the central cube in a spherical fashion.
    I also need this rotation to use the keyboard arrow keys, not the mouse because I am reserving the mouse for interaction using the PickMouseBehavior class as stated in my project specification.
    I have looked up various classes in the API: such as KeyNavigator, OrbitBehavior, and some VisAd class that isn't included with the Java3D API nor is it on the systems I have available at the university.
    The trouble is, all these classes that I have found do not rotate the way I need them to: as described above. They "turn left" and "turn right" the camera as opposed to "rotate left around" and "rotate right around" the central cube (i.e horizontal rotation of the camera on a wide circle around an object).
    They also "move forward" and "move backward" as opposed to "rise up around" and "drop down around" the central cube (i.e. vertical rotation on a wide circle around an object).
    I have previously tackled this problem by creating a dummy cube under the central cube using then attaching the "camera" to the dummy cube in the DarkBASIC programming language and wonder if this method is available using Java.
    I've thought about defining my own arrow key rotation class, but I have little idea how to go about doing that either.
    An additional bonus would be the ability to limit vertical rotation so as not to go over and upside-down the vertical limit.
    Any help would be appreciated.

    I appreciate the answer and I know about implementing a Behavior to do this particular function of the program: is this what you are suggesting?
    If so, could you provide some clarity onto how go about implementing a Behavior to do the type of rotations I stated in my first post? By clarity I mean a little bit more about the recipe for creating a Behavior: the API is lacking documentation on this I think.
    I'll go do a bit of reading on it and tell you where I get. Nonetheless, any further advice would be much appreciated.

  • Last Project -- Need Help, Please

    Okay, this is my last project, and I am struggling with it. The specification we were given was to write a program that reads in a file of dates and outputs the dates in descending order, using a priority queue. The PriorityQueue should implement the PriorityQueueInterface interface, and should implements a priority queue using a singly linked list. The list should be maintained in sorted order. This implementation should not use a heap.
    I have the code built, but when I run it is not reading my dates fully, and I get an error message. The LinkList is already built for us, but here is the rest of my code. First I input from my dates.txt:
    11/12/2000
    04/04/2004
    01/02/1998
    import java.io.*;
    public class DateDriver {
       public static void main(String[] args) throws IOException {
          PriorityQueue pq = new PriorityQueue();
          // ... read all Date objects from the file and enqueue them in the pq object
          BufferedReader in = new BufferedReader (new FileReader("C:/Users/April/Desktop/UMUC/CMIS241/Project4/Dates.txt"));
          Date date = new Date();
          date.input(in);
          while (!date.isNull()){
               pq.add(date);
               date = new Date();
               date.input(in);
               System.out.println(date);
          // ... dequeue the pq object and display the Date objects
          System.out.println("The dates in descending order are: ");
          while (!pq.isEmpty()){
               date = (Date) pq.dequeue();
               date.output(System.out);
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.PrintStream;
    public class Date implements InOutputable, Comparable {
       // ... define monthNames as a ?static final? array of String objects
       //  initialize the array with the first 3 characters of each month
         static final String[] monthNames = {null, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
              "Oct", "Nov", "Dec"};
       // ... define the instance variables of class Date, i.e. day, month, year
         private String monthAbr, date;
         private int month, day, year;
       // ... define the default constructor (initializes the instance variables to zero)
         public Date(){
              this.date = "";
              month = 00;
              day = 00;
              year = 0000;
       // ... define the method toString
       //     This method should return the corresponding Date string in the following format: Nov, 11, 2006
         public String toString() {
               return (monthAbr + ", " + day + ", " + year);
       // ... define the methods specified by the interface InOutputable
    public boolean equals(InOutputable other) {
         Date otherDate = (Date) other;
         if (month == otherDate.month && day == otherDate.day && year == otherDate.year)
              return true;
         else
              return false;
    public void input(BufferedReader in) throws IOException {
         date = in.readLine();
         if (date == null)
              return;
         month = Integer.parseInt(date.substring(0, 2));
         day = Integer.parseInt(date.substring(3, 5));
         year = Integer.parseInt(date.substring(6, 10));
    public boolean isNull() {
         if (month == 0 && day == 0 && year == 0)
              return true;
         else
              return false;
    public void output(PrintStream writer) {
         writer.println(toString());
       // ... define the method specified by the interface Comparable
    public int compareTo(Object o) {
         Date otherDate = (Date) o;
         if(month == otherDate.month && day == otherDate.day && year == otherDate.year)
              return 0;
         else if (month >= otherDate.month && day >= otherDate.day && year >= otherDate.year)
              return 1;
         else
              return -1;
    public class PriorityQueue implements PriorityQueueInterface {   
       private RefSortedList lst = new RefSortedList();
       // ... define the methods specified by the interface PriorityQueueInterface
    public Comparable dequeue() throws EmptyQueue {
         return null;
    public void enqueue(Comparable key) throws FullQueue {
    public boolean isEmpty() {
         return false;
       // ... Use the lst object (by invoking list specific methods on it) when
       //     defining the PriorityQueueInterface methods.
       //     For example, method enqueue should be implemented by invoking list method add.
    public void add(Date date){
         lst.add(date);
    public void remove(Date date){
         lst.remove(date);
    }My output:
    Exception in thread "main" java.lang.NullPointerException
         at DateDriver.main(DateDriver.java:27)
    null, 4, 2004
    null, 2, 1998
    null, 0, 0
    The dates in descending order are:
    Can anybody please point me in the right direction? I know I am missing something, but I am unable to pinpoint it. I don't understand why the date.output(System.out) is throwing a null pointer exception. I am still working, but I thought maybe a fresh pair of eyes would help me.

    Dates implement Comparable... no need to sort them yourself
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    LinkedList<Date> dtes = new LinkedList<Date>();
    BufferedReader in = new BufferedReader (new FileReader("C:/dates.txt"));
    while (in.read()>0){
    dtes.add(sdf.parse(in.readLine()));
    }Edited by: wpp289 on Dec 11, 2008 1:27 PM

  • Massive iDVD project-Need help breaking it up

    I have been working on a comprehensive DVD of all of my family photos dating back to 1890. I have chapters split up by decades and then submenus within divided up by years. It is almost 2000 photos (no iMovies). Each year is its own slideshow with music attached (slideshow created within iDVD). The monster is 16gigs and over 800 minutes long (according to the project info), however, if you just add up each slideshow it only adds up to about 4 hours of material. I have a red "X" in the top box of my map view that says "total menu duration exceeds 15 minutes", however when I duplicate the project and start deleting chapters it never goes away.
    Is there away to easily split this project up into 2 or 3 DVD's?
    Or perhaps make the menus smaller?
    No one slide show is more than 13 minutes long.
    I am open to suggestions on how to tame this bohemoth.
    Thanks!

    As much as you would like it to be all on one DVD, clearly you need to break it up, unless you really want to burn it to a double layer DVD, which can accomodate 4 hours. This includes all the menus.
    I would break it up into two or three DVDs, by doing just what you tried; duplicate the DVD project and then delete the parts you don't want in the duplicates,so that you end up with 2 or 3 DVDs of 2hrs or 1 1/2hrs each. Since you already have them organized into years, it should be simple enough to do.

  • Class final project need help

    I have this final project due Monday for my java class. I'm having some trouble with this zoom slider which gives me 2 errors about "cannot find symbol". I've tried just about eveything i can think of and i cant come up with the solution... Here is my code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.io.*;
    public class MenuExp extends JFrame implements MouseMotionListener,MouseListener,ActionListener
    /* creates the file menus and submenus */
         JMenu fileMenu = new JMenu("File");
        JMenu plotMenu = new JMenu("Plotting");
        JMenu helpMenu = new JMenu("Help");
        JMenuItem loadAction = new JMenuItem("Load");
        JMenuItem saveAction = new JMenuItem("Save");
        JMenuItem quitAction = new JMenuItem("Quit");
        JMenuItem colorAction = new JMenuItem("Segment Colors");
        JMenuItem helpAction = new JMenuItem("Instructions");
        JButton button;
         Cursor previousCursor = new Cursor(Cursor.DEFAULT_CURSOR);
        JLabel cLabel;
        JPanel cPanel;
        private String filename = null;  // set by "Open" or "Save As"
        double scale = 1.0;
        public MenuExp(File f)
            setTitle("PlotVac");
            Container pane = getContentPane();
            ImageIcon chartImage = new ImageIcon(f.getName());
              ChartDisplay chartLabel = new ChartDisplay(chartImage);
              JScrollPane scpane = new JScrollPane(chartLabel);
              pane.add(scpane, BorderLayout.CENTER);
              chartLabel.addMouseListener(this);  //change cursor
              chartLabel.addMouseMotionListener(this); //handle mouse movement
              JPanel cPanel = new JPanel();
              cLabel= new JLabel("cursor outside chart");
              cPanel.add(cLabel);
              pane.add(cPanel, BorderLayout.NORTH);
              button = new JButton("Clear Route");
            button.setAlignmentX(Component.LEFT_ALIGNMENT);
            button.setFont(new Font("serif", Font.PLAIN, 14));
              cPanel.add(button);
              getContentPane().add(getSlider(), "Last");
    /* Creates a menubar for a JFrame */
            JMenuBar menuBar = new JMenuBar();
    /* Add the menubar to the frame */
            setJMenuBar(menuBar);
    /* Define and add three drop down menu to the menubar */
            menuBar.add(fileMenu);
            menuBar.add(plotMenu);
            menuBar.add(helpMenu);
    /* Create and add simple menu item to the drop down menu */
            fileMenu.add(loadAction);
            fileMenu.add(saveAction);
            fileMenu.addSeparator();
            fileMenu.add(quitAction);
            plotMenu.add(colorAction);
            helpMenu.add(helpAction);
             loadAction.addActionListener(this);
             saveAction.addActionListener(this);
             quitAction.addActionListener(this);
        private JSlider getSlider()
            JSlider slider = new JSlider(25, 200, 100);
            slider.setMinorTickSpacing(5);
            slider.setMajorTickSpacing(25);
            slider.setPaintTicks(true);
            slider.setPaintLabels(true);
            slider.addChangeListener(new ChangeListener()
                public void stateChanged(ChangeEvent e)
                     int value = ((JSlider)e.getSource()).getValue();
                     cPanel.zoom(value/100.0);
            return slider;
        private void zoom(double scale)
            this.scale = scale;
            cPanel.setToScale(scale, scale);
            repaint();
    /* Handle menu events. */
           public void actionPerformed(ActionEvent e)
              if (e.getSource() == loadAction)
                   loadFile();
             else if (e.getSource() == saveAction)
                    saveFile(filename);
             else if (e.getSource() == quitAction)
                   System.exit(0);
    /** Prompt user to enter filename and load file.  Allow user to cancel. */
    /* If file is not found, pop up an error and leave screen contents
    /* and filename unchanged. */
           private void loadFile()
             JFileChooser fc = new JFileChooser();
             String name = null;
             if (fc.showOpenDialog(null) != JFileChooser.CANCEL_OPTION)
                    name = fc.getSelectedFile().getAbsolutePath();
             else
                    return;  // user cancelled
             try
                    Scanner in = new Scanner(new File(name));  // might fail
                    filename = name;
                    while (in.hasNext())
                    in.close();
             catch (FileNotFoundException e)
                    JOptionPane.showMessageDialog(null, "File not found: " + name,
                     "Error", JOptionPane.ERROR_MESSAGE);
    /* Save named file.  If name is null, prompt user and assign to filename.
    /* Allow user to cancel, leaving filename null.  Tell user if save is
    /* successful. */
           private void saveFile(String name)
             if (name == null)
                    JFileChooser fc = new JFileChooser();
                    if (fc.showSaveDialog(null) != JFileChooser.CANCEL_OPTION)
                      name = fc.getSelectedFile().getAbsolutePath();
             if (name != null)
                  try
                      Formatter out = new Formatter(new File(name));  // might fail
                        filename = name;
                      out.close();
                      JOptionPane.showMessageDialog(null, "Saved to " + filename,
                        "Save File", JOptionPane.PLAIN_MESSAGE);
                    catch (FileNotFoundException e)
                      JOptionPane.showMessageDialog(null, "Cannot write to file: " + name,
                       "Error", JOptionPane.ERROR_MESSAGE);
    /* implement MouseMotionListener methods */     
         public void mouseDragged(MouseEvent arg0)
         public void mouseMoved(MouseEvent arg0)
              int x = arg0.getX();
              int y = arg0.getY();
              cLabel.setText("X pixel coordiate: " + x + "     Y pixel coordinate: " + y);
    /*      implement MouseListener methods */
         public void mouseClicked(MouseEvent arg0)
         public void mouseEntered(MouseEvent arg0)
             previousCursor = getCursor();
             setCursor(new Cursor (Cursor.CROSSHAIR_CURSOR) );
         public void mouseExited(MouseEvent arg0)
             setCursor(previousCursor);
             cLabel.setText("cursor outside chart");
         public void mousePressed(MouseEvent arg0)
         public void mouseReleased(MouseEvent arg0)
    /* main method to execute demo */          
        public static void main(String[] args)
             File chart = new File("teritory-map.gif");
            MenuExp me = new MenuExp(chart);
            me.setSize(1000,1000);
            me.setLocationRelativeTo(null);
            me.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            me.setVisible(true);
    }and this is the other part:
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.geom.Line2D;
    import javax.swing.Icon;
    import javax.swing.JLabel;
    public class ChartDisplay extends JLabel
    /* line at 45 degrees from horizontal */
         private int x1=884, y1=290, x2=1084, y2=490;
    /* horizontal line - x3 same as x2 */
         private int x3=1084, y3=490, x4=1384, y4=490;
         public ChartDisplay(Icon arg0)
              super(arg0);
    /* This overrides inherited method to draw on image */
         protected void paintComponent(Graphics arg0)
              super.paintComponent(arg0);
    /* Utility method to draw a "dot" at line ends */
         private void drawDot(Graphics g, Color c, int xDot, int yDot, int sizeDot)
              Color previousColor = g.getColor();
              g.setColor(c);
                g.fillOval(xDot-(sizeDot/2), yDot-(sizeDot/2), sizeDot, sizeDot);
                g.setColor(previousColor);   
    /* Utility method to draw a wider line */
         private void drawLine(Graphics g, Color c, int lineWidth, int xStart, int yStart, int xEnd, int yEnd)
              Color previousColor = g.getColor(); // save previous color
              Graphics2D g2 = (Graphics2D) g;  // access 2D properties
                g2.setPaint(c);  // use color provided as parameter
             g2.setStroke(new BasicStroke(lineWidth)); // line width
             g.setColor(previousColor);    // restore previous color
    }I've basically used the structure of other programs and incorporated them into my design. If anyone knows how i can fix the errors please let me know. The errors are found in line 91 and 100 which is where the zoom slider is occuring.
    **NOTE** the program isnt fully functional in the sense that there are buttons and tabs etc.. that are missing action listeners and things like that.
    Thanks for the help
    Edited by: gonzale3 on Apr 17, 2008 6:55 PM

    gonzale3 wrote:
    The code was on the forums as the person who posted it was using it as an example in a program he used... i didnt borrow the entire code im just using the way he did the zoom method and added it into my program. I wasnt aware that it was used in the JPanel class. C'mon, it's your program. If you don't know what you are doing in this program, then you shouldn't be using it.
    That is why im asking if someone can show me the right way to implement a zoom slider into my program or maybe give me an example where its used.What the fuck is a zoom slider???
    Edited by: Encephalopathic on Apr 17, 2008 8:00 PM

  • Final year project need help

    hi there
    i am doing an applet for my final year project. at the end of this project i have to end up with a simple uml drawing applet. i have done some coding but am way outa my league and now i am stuck. i have managed to draw lines and rectangles but have no idea how to make the lines attch to the rectangles or how to move a rectangle around the screenonce it has been drawn. my email address is [email protected] if you mail me i can give you my program and maybe you can help me

    You are right V.V, this applet is not finished yet, try this one,
    press the oval/rectangle/desic buttons and add shapes by clicking on an empty square, after adding some shapes press the line button, by clicking on 2 shapes you will add a line to connect them. you can drag the shapes and the lines will follow.
    Use double click for text. Drag the shape out of the screen and it will be deleted.
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class Flow extends Applet
         Button lineB = new Button("Line");
         Button rectB = new Button("Rect");
         Button ovalB = new Button("Oval");
         Button desiB = new Button("Desic");
         Button clirB = new Button("Clear");
         Label  typeL = new Label("             ");
         Dcanvas  canvas     = new Dcanvas();
    public void init()
         setLayout(new BorderLayout());
         add("Center",canvas);
         addButtons();
         resize(730,440);
    private void addButtons()
         lineB.addActionListener(new ButtonHandler());
         rectB.addActionListener(new ButtonHandler());
         ovalB.addActionListener(new ButtonHandler());
         desiB.addActionListener(new ButtonHandler());
         clirB.addActionListener(new ButtonHandler());
         Panel panel = new Panel();
         panel.add(lineB);
         panel.add(rectB);
         panel.add(ovalB);
         panel.add(desiB);
         panel.add(clirB);
         panel.add(typeL);
         add("North",panel);
    class ButtonHandler implements ActionListener
    public void actionPerformed(ActionEvent ev)
         String s = ev.getActionCommand();
         if(s.equals("Clear")) canvas.clear();
         if(s.equals("Line"))  canvas.setType(1);
         if(s.equals("Rect"))  canvas.setType(2);
         if(s.equals("Oval"))  canvas.setType(3);
         if(s.equals("Desic")) canvas.setType(4);
    public class Dcanvas extends Panel
         Vector    objects = new Vector();
         Vector    lines   = new Vector();
         TextField txt     = new TextField("");
         Mobject   rc,rl,rd;
         Mline     ln;
         boolean   rcd  = false;
         boolean   rcl  = false;
         boolean   rct  = false;
         Rectangle rp;
         Graphics2D G;
         int sx,sy,oi;
         int objectType = 0;     
         int maxV = 8;
         int maxH = 9;
         int sizeW = 80;
         int sizeH = 50;
    public Dcanvas()
         super();
         setLayout(null);
         addMouseListener(new MouseHandler());
         addMouseMotionListener(new MouseMotionHandler());
         setFont(new Font("",0,9));
         txt.setSize(114,23);
         txt.setFont(new Font("",0,15));
         txt.setBackground(new Color(192,220,192));
         add(txt);
         txt.setVisible(false);
         txt.addTextListener(new TextListener()     
         {     public void textValueChanged(TextEvent e)
                   rc.setText(txt.getText());     
                   repaint(rc.x,rc.y,rc.width,rc.height);
    public void clear()
         objects.removeAllElements();
         lines.removeAllElements();
         objectType = 0;
         typeL.setBackground(Color.white);
         typeL.setText("");
         txt.setVisible(false);
         repaint();
    public void setType(int i)
         if (rcl) repaint(rl.x,rl.y,rl.width+1,rl.height+1);
         objectType = i;
         typeL.setBackground(Color.pink);
         if (i == 1)     typeL.setText(" Lines");
         if (i == 2)     typeL.setText(" Rects");
         if (i == 3)     typeL.setText(" Ovals");
         if (i == 4)     typeL.setText(" Desic");
         rcl = false;
    public void dragIt(int X, int Y)
         repaint(rc.x,rc.y,rc.width,rc.height);
         rc.x = rc.x + X - sx;
         rc.y = rc.y + Y - sy;
         rc.setPaintArea();
         sx   = X;
         sy   = Y;
         repaint(rc.x,rc.y,rc.width,rc.height);
    public void moveIt(int X, int Y)
         rcd = false;
         repaint(rc.x,rc.y,rc.width,rc.height);
         rc.x = X;
         rc.y = Y;
         rc.setPaintArea();
         repaint(rc.x,rc.y,rc.width,rc.height);
         Mline ml;
         for (int i=0; i < lines.size(); i++)
              ml = (Mline)lines.get(i);
              if (ml.from == rd || ml.to == rd)
                   ml.setPaintArea();
                   repaint();
    public void deleteIt()
         rcd = false;
         Mline ml;
         for (int i=0; i < lines.size(); i++)
              ml = (Mline)lines.get(i);
              if (ml.from == rd || ml.to == rd)
                   lines.remove(i);
                   i--;
         objects.remove(rc);
         repaint();
    public void paint(Graphics g)
         rp = g.getClipBounds();
         g.setColor(Color.white);
         g.fillRect(rp.x,rp.y,rp.width,rp.height);
         g.setColor(new Color(240,240,240));
         for (int x=0; x < 721; x=x+sizeW) g.drawLine(x,0,x,400);
         for (int y=0; y < 401; y=y+sizeH) g.drawLine(0,y,720,y);
         for (int i=0; i < lines.size(); i++) ((Mline)lines.get(i)).paint(g);
         for (int i=0; i < objects.size(); i++) ((Mobject)objects.get(i)).paintW(g);
         if (rcd) rc.paintD(g);
         if (rcl) rc.paintL(g);
    public void update(Graphics g)
         paint(g);
    //     *********   mouse   ************
    class MouseHandler extends MouseAdapter
    public void mousePressed(MouseEvent e)
         txt.setVisible(false);
         for (int i=0; i < objects.size(); i++)
              if (((Rectangle)objects.get(i)).contains(e.getX(),e.getY()))
                   rc  = (Mobject)objects.get(i);
                   rd  = rc;
                   sx  = e.getX();
                   sy  = e.getY();
                   if (e. getClickCount() == 2)  
                        txt.setLocation(rc.x,rc.y+rc.height-1);
                        txt.setText(rc.getText());
                        txt.setVisible(true);
                        txt.requestFocus();
                   rcd = true;
         if (rcd && rcl)
              ln  = new Mline(rl,rc);
              lines.add(ln);
              rcd = false;
              rcl = false;
              rp.setBounds(rc);
              rp.add(rl);
              repaint(rp.x,rp.y,rp.width,rp.height);
         if (rcd && objectType == 1)
              rcd = false;
              rcl = true;
              rl  = rc;
              repaint(rc.x,rc.y,rc.width,rc.height);
    public void mouseReleased(MouseEvent e)
         int x = e.getX()/sizeW;
         int y = e.getY()/sizeH;
         x = x * sizeW + 1;
         y = y * sizeH + 1;
         if (rcd)
              if (x > maxH || y > maxV) deleteIt();
                   else                  moveIt(x,y);
              return;     
         if (objectType == 2 || objectType == 3 || objectType == 4)
              rc = new Mobject(objectType,x,y,sizeW-2,sizeH-2);
              objects.add(rc);
              repaint(rc.x,rc.y,rc.width,rc.height);
    class MouseMotionHandler extends MouseMotionAdapter
    public void mouseDragged(MouseEvent e)
         if (rcd) dragIt(e.getX(),e.getY());
    //     *********   mouse  end ************
    class Mobject extends Rectangle
         long    id;
         int     type;
         int     ax,ay,aw,ah;
         String  text = "";
         Polygon po   = new Polygon();
    public Mobject(int t, int x,int y,int w,int h)
         super(x,y,w,h);
         type = t;
         setPaintArea();
         type = t;
         id = System.currentTimeMillis();
    public void setText(String s)
         text = s;
    public String getText()
         return(text);
    public void setPaintArea()
         ax = x + 5;
         ay = y + 5;
         aw = width  - 10;
         ah = height - 10;
         if (type == 4)
              po.npoints = 0;
              po.addPoint(ax+aw/2,ay);
              po.addPoint(ax+aw,ay+ah/2);
              po.addPoint(ax+aw/2,ay+ah);
              po.addPoint(ax,ay+ah/2);
              po.addPoint(ax+aw/2,ay);
    public void paintL(Graphics g)
         g.setColor(Color.orange);
         paint(g);
    public void paintD(Graphics g)
         g.setColor(Color.red);
         paint(g);
    public void paintW(Graphics g)
         g.setColor(Color.white);
         paint(g);
    public void paint(Graphics g)
         if (type == 2) g.fillRect(ax,ay,aw,ah);
         if (type == 3) g.fillOval(ax,ay,aw,ah);
         if (type == 4) g.fillPolygon(po);
         g.setColor(Color.black);
         if (type == 2) g.drawRect(ax,ay,aw,ah);
         if (type == 3) g.drawOval(ax,ay,aw,ah);
         if (type == 4) g.drawPolygon(po);
         g.drawString(text,ax+3,ay+ah/2+2);
    class Mline
         Mobject from,to;
         int x1,y1,x2,y2;
    public Mline(Mobject f, Mobject t)
         from = f;
         to   = t;
         setPaintArea();
    public void setPaintArea()
         x1 = from.x + from.width/2;
         y1 = from.y + from.height/2;
         x2 = to.x + to.width/2;
         y2 = to.y + to.height/2;
    public void paint(Graphics g)
         g.setColor(Color.blue);
         g.drawLine(x1,y1,x2,y2);
    Noah

  • New to SAP FICO - Placed in a support project - Need Help

    Hi everyone,
    I have placed for a support project in a retail industry and I have been taken FICO as my module. Can you guys help me in knowing what all things I have to do in the initial stage
    Regards,
    Prajeesh
    SAP FICO Consultant
    Moderator: Please, read and respect SDN rules

    They are in the same path in the jar file that they were when they were on your disk in the file system. Lets say you have a dir structure
    C:\dir1\dir2\dir3\dir4\file.txt
    and you cd to dir2:
    cd \dir1\dir2
    then you jar dir3:
    jar cvf jar.jar dir3/*.*
    the path to file.txt would still be /dir3/dir4/file.txt inside the jar file.
    do a jar tvf jarfile.jar and take a look.

  • At wit's end with imovie project -- need Help!

    Aloha:
    I am in the middle of doing a documentary movie of the yearly Air Show put on by my RC model airplane club. Over the past several years I have made a handful of other documentaries and all with out problem, they worked just fine.
    On this one, however, I have run into problems that are new and completely frustrating. I have finished editing the movie and all works well in the iMovie mode. I can play the entire movie and all the parts and pieces work just fine. But when I burn the results onto a DVD some scenes (only a few) lose camera audio. This is also true if I export it to Quicktime.
    My movie uses camera audio, imported background music and narrative voice-over. And all those play just fine in the iMovie program. But there are several spots where the camera audio doesn't come across in the final product, just total silence except for the background music or any voice-over narrations that may be present during those times. The camera audio just does not come through.
    I am at wit’s end and need some help. Has anyone come across this and what did you do to fix it?
    Thanks
    Dan Page
    Maui, Hawaii

    Hi: Thank you very much for the rapid come back, most appreciated.
    Hi Dan
    A wild guess. Can it be so that those clips are
    recorded in Your Camera with
    the sound set to 12-bit (often factory/default set).
    Should be 16-bit
    I'll check the camera for that, but the same camera was used in all the clips and only two or three were missing audio when exported.
    Try to extract the missing sounds from each clip and
    redo a disk image in
    iDVD and see if the sound is back.
    That sounds like a great diagnostic and should be far less time consuming than burning a DVD.
    Thanks for the hints.
    Dan Page
    Yours Bengt W

  • Getting codec error in  a fcp project NEED HELP ASAP

    All of my other projects seem to be working fine, but one project in Paticular when I try to export using "quickime conversion" I get a codec error....as soon as I hit enter...therefore I cannot get it to convert to a quicktime file.
    I went an checked another project and it converted fine, it's just this one. how can I trouble shoot this.

    Just copy what's in the sequence. This is just a quick fix if it works. You would still probably want to figure out what happened in the old project to avoid it in the future.
    Seems like maybe you have the wrong sequence settings or something. Others here would be better equipped to troubleshoot it.
    Good Luck.

  • Uni Game project, need help

    hi, i have an assignment for uni where i have to make a text game according to a given scenario, a part of the game has a bomb room and a bomb timer, where if the player doesent get the code right within 10 seconds the bomb explodes and the player has the choice to restart.
    here is the code to the bomb, im not sure if the sleep method timer is causing the problems, it runs, but when you choose y to restart it just goes into this error:
    Exception in thread "main" java.util.InputMismatchException
    at java.util.Scanner.throwFor(Scanner.java:840)
    at java.util.Scanner.next(Scanner.java:1461)
    at java.util.Scanner.nextInt(Scanner.java:2091)
    at java.util.Scanner.nextInt(Scanner.java:2050)
    at hostage.Main.main(Main.java:134)
    here is the code:
         boolean go = true;
         boolean countfinish = false;
         Scanner sc = new Scanner(System.in);
         int rn1, rn2, answer, sumofrn1rn2;
         boolean restart = true;
         System.out.println("you have entered the BOMB ROOM!!! solve the equasion within 10 seconds to defuse the bomb");
         System.out.println();
    //below is the equasion to defuse the bomb     
    rn1 = (int)(Math.random()*1000);
    rn2 = (int)(Math.random()*1000);
         System.out.print(rn1);
         System.out.print(" + ");
         System.out.print(rn2);
         System.out.print(" = ");
         answer = 0;
         sumofrn1rn2 = (rn1+rn2);
         try
    // the sleep method of the thread object is called
    Thread.sleep(10000);
    catch(InterruptedException e)
    countfinish = true;
    if (countfinish == true)
         if (sumofrn1rn2 != answer)
    System.out.println("You faild, oh and your dead... Restart? (y/n)");
    restart2 = sc.next().charAt(0);
    if (restart2 == 'y')     
         Current_Room = "ROOM 1";
         System.out.println("Welcome to the Lobby!.....again....");
         answer = sc.nextInt();
         if (answer == rn1+rn2)
              System.out.println("You have defused the bomb... fewww...");
              //go back to lobby
    any help would be appresiated, thank you

    No problem. One thing that I noticed after testing it out for a bit more...
    With those implementations, you only get 1 guess, which I suppose is accurate to real life. If you want them to be able to have multiple guesses then, here's some new implementation
    import java.util.Timer;
    import java.util.TimerTask;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.util.Random;
    public class BombGameTest
         private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         private boolean failed = false;
         public static void main(String[] args)
              new BombGameTest().bombTest();
         public void bombTest()
              class ExplodeBomb extends TimerTask
                   int timeLeft = 10;
                   public void run()
                        if (timeLeft != 0)
                             System.out.println(timeLeft-- + "...");
                        else
                             System.out.println();
                             failed = true;
                             System.out.println("You failed to difuse the bomb, you are now dead. Restart? [y/n] ");
                             String tmp = "";
                             try
                                  tmp = br.readLine();     //Like the Scanner.nextLine();
                             } catch(Exception ex) {}
                             if (tmp.toUpperCase().equals("Y"))
                                  //run some restart method
                             else
                                  System.exit(0);
              System.out.println("You have entered the BOMB ROOM!!! Solve the equation within 10 seconds to defuse the bomb.");
              System.out.println();
              Random randGen = new Random();
              int r1 = randGen.nextInt(1000);     //basically the same as the random() method
              int r2 = randGen.nextInt(1000);
              System.out.print(r1);
              System.out.print(" + ");
              System.out.print(r2);
              System.out.println(" = ? ");
              Timer t = new Timer();
              t.scheduleAtFixedRate(new ExplodeBomb(), 0,1000);
              int answer = 0;
              boolean incorrect = true;
              while (incorrect)
                   try
                        answer = Integer.parseInt(br.readLine());
                   } catch (Exception ex) {}
                   if (answer == r1 + r2 && !failed)
                        t.cancel();
                        System.out.println("Congrats! You defused the bomb.");
                        incorrect = false;
    }

  • Need help with project

    Hi all I'm working on a project and need help.
    I want the "New" button to clear all the fields.
    Any help?
    =======================================================
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Message extends JFrame implements ActionListener {
         public Message() {
         super("Write a Message - by Kieran Hannigan");
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setSize(370,270);
         FlowLayout flo = new FlowLayout(FlowLayout.RIGHT);
         setLayout(flo);
         //Make the bar
         JMenuBar bar = new JMenuBar();
         //Make "File" on Menu
         JMenu File = new JMenu("File");
         JMenuItem f1 = new JMenuItem("New");
         JMenuItem f2 = new JMenuItem("Open");
         JMenuItem f3 = new JMenuItem("Save");
         JMenuItem f4 = new JMenuItem("Save As");
         JMenuItem f5 = new JMenuItem("Exit");
         File.add(f1);
         File.add(f2);
         File.add(f3);
         File.add(f4);
         File.add(f5);
         bar.add(File);
         //Make "Edit" on menu
         JMenu Edit = new JMenu("Edit");
         JMenuItem e1 = new JMenuItem("Cut");
         JMenuItem e2 = new JMenuItem("Paste");
         JMenuItem e3 = new JMenuItem("Copy");
         JMenuItem e4 = new JMenuItem("Repeat");
         JMenuItem e5 = new JMenuItem("Undo");
         Edit.add(e5);
         Edit.add(e4);
         Edit.add(e1);
         Edit.add(e3);
         Edit.add(e2);
         bar.add(Edit);
         //Make "View" on menu
         JMenu View = new JMenu("View");
         JMenuItem v1 = new JMenuItem("Bold");
         JMenuItem v2 = new JMenuItem("Italic");
         JMenuItem v3 = new JMenuItem("Normal");
         JMenuItem v4 = new JMenuItem("Bold-Italic");
         View.add(v1);
         View.add(v2);
         View.add(v3);
         View.addSeparator();
         View.add(v4);
         bar.add(View);
         //Make "Help" on menu
         JMenu Help = new JMenu("Help");
         JMenuItem h1 = new JMenuItem("Help Online");
         JMenuItem h2 = new JMenuItem("E-mail Programmer");
         Help.add(h1);
         Help.add(h2);
         bar.add(Help);
         setJMenuBar(bar);
         //Make Contents of window.
         //Make "Subject" text field
         JPanel row2 = new JPanel();
         JLabel sublabel = new JLabel("Subject:");
         row2.add(sublabel);
         JTextField text2 = new JTextField("RE:",24);
         row2.add(text2);
         //Make "To" text field
         JPanel row1 = new JPanel();
         JLabel tolabel = new JLabel("To:");
         row1.add(tolabel);
         JTextField text1 = new JTextField(24);
         row1.add(text1);
         //Make "Message" text area
         JPanel row3 = new JPanel();
         JLabel Meslabel = new JLabel("Message:");
         row3.add(Meslabel);
         JTextArea text3 = new JTextArea(6,22);
         messagearea.setLineWrap(true);
         messagearea.setWrapStyleWord(true);
         JScrollPane scroll = new JScrollPane(text3,
                                  JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                                  JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
         row3.add(scroll);
         add(row1);
         add(row2);
         add(row3);
         setVisible(true);
         public static void main(String[] arguments)  {
         Message Message = new Message();
    }

    Ok, given that I may have not been the kindest to you on the other thread (and I'm still annoyed that you went and cross-posted this), and that you did actually use code tags, I'm going to post some code here:
    Please take the following advice onboard though.
    1. When you are naming your artifacts, please use the java coding standard as your guide. So if you are naming a class you use a capital letter first, and use camel case thereafter. All method names begin with a lower case letter, and all variable names begin with a lower case letter (and again camel case after that)
    2. Please use self explanitory names (for everything), so no more row1, row2, or text1, text2, etc.
    3. The example I am giving below makes use of a single class to handle all actions, this is not really the best way to do this, and a better way would be to have a class to handle each action (that would remove the massive if() else if() in the action handler class.
    4. When you are using class variables they should be private (no exceptions, ever!), if you need to access them from other classes use accessors (eclipse and other IDE tools can generate these methods for you in seconds)
    5. Notice the naming convention for my constants (final statics), they are all upper case (again from the java coding standards document, which you are going to look for with google right?)
    6. I have hived some of the creation work to helper methods (the getSubjectTextField() etc), although it isn't advisable to be calling other methods from the constructor, since this is a GUI, and you want it to appear as soon as you create the class, we won't worry about this, but perhaps as an execrise you could work out a better way to do this?
    7. Personally, I don't like classes that implement listeners, unless they are specifically designed to do that job. So a Frame that is set up as an action listener is fine, provided the actions it listens for are associated with the frame, not its contents. If the actions are related to its contents, then a dedicated class is better.
    8. Another personal opinion, but I feel it makes code clearer, but others may disagree. If you are creating a variable solely to hold the result of a calculation, to be passed to a method in the very next line, then don't create the variable, just pass the method as the argument to the method (feel free to ignore this advice if the method call is extremely long, and a local would make it easier to read)
    Anyway, here is the code. I have removed most of the menu items, and leave this as an exercise for you. Also I have only created 2 methods (new and exit), I'll again leave it as an exercise for you to complete this.
    package jdc;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import javax.swing.AbstractAction;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.ScrollPaneConstants;
    public class Message extends JFrame {
        /** Constant for the new action command. */
        private static final String NEW_COMMAND = "New";
        /** Constant for the exit action command. */
        private static final String EXIT_COMMAND = "Exit";
        /** Subject text field. */
        private JTextField subjectTextField;
        /** Recipient text field. */
        private JTextField toTextField;
        /** Message text area. */
        private JTextArea messageTextArea;
        public Message() {
            super("Write a Message - by Kieran Hannigan");
            setSize(370, 270);
            FlowLayout flo = new FlowLayout(FlowLayout.RIGHT);
            setLayout(flo);
            setJMenuBar(createMenuBar());
            // Add "Subject" text field
            JPanel subjectRow = new JPanel();
            subjectRow.add(new JLabel("Subject:"));
            subjectRow.add(getSubjectTextField());
            // Add "To" text field
            JPanel toRow = new JPanel();
            toRow.add(new JLabel("To:"));
            toRow.add(getToTextField());
            // Make "Message" text area
            JPanel messageRow = new JPanel();
            JScrollPane scroll = new JScrollPane(getMessageTextArea(), ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            messageRow.add(scroll);
            add(toRow);
            add(subjectRow);
            add(messageRow);
            setVisible(true);
         * Clear all the fields.
        public void createNewMessage() {
            getSubjectTextField().setText("");
            getToTextField().setText("");
            getMessageTextArea().setText("");
         * Exit the application.
        public void exitApplication() {
            if (JOptionPane.showConfirmDialog(this, "Are you sure you would like to exit now?", "Exit",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                System.exit(0);
         * @return The subject text field, (creates a new one if it doesn't already exist)
        private JTextField getSubjectTextField() {
            if (this.subjectTextField == null) {
                this.subjectTextField = new JTextField("RE:", 24);
            return this.subjectTextField;
         * @return The to text field, (creates a new one if it doesn't already exist)
        private JTextField getToTextField() {
            if (this.toTextField == null) {
                this.toTextField = new JTextField(24);
            return this.toTextField;
         * @return The message text area, (creates a new one if it doesn't already exist
        private JTextArea getMessageTextArea() {
            if (this.messageTextArea == null) {
                this.messageTextArea = new JTextArea(6, 22);
                this.messageTextArea.setLineWrap(true);
                this.messageTextArea.setWrapStyleWord(true);
            return this.messageTextArea;
         * Helper method to create the menu bar.
         * @return Menu bar with all menus and menu items added
        private JMenuBar createMenuBar() {
            JMenuBar bar = new JMenuBar();
            JMenu fileMenu = new JMenu("File");
            fileMenu.add(new JMenuItem(new MenuItemAction(this, NEW_COMMAND)));
            fileMenu.add(new JMenuItem(new MenuItemAction(this, EXIT_COMMAND)));
            bar.add(fileMenu);
            // TODO add all other menu's and menu items here....
            return bar;
         * Private static class to handle all menu item actions.
        private static class MenuItemAction extends AbstractAction {
            /** Instance of the message class. */
            private Message message;
             * @param actionName
            public MenuItemAction(Message messageFrame, String actionName) {
                super(actionName);
                this.message = messageFrame;
             * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
            public void actionPerformed(ActionEvent e) {
                if (e.getActionCommand().equals(NEW_COMMAND)) {
                    this.message.createNewMessage();
                } else if (e.getActionCommand().equals(EXIT_COMMAND)) {
                    this.message.exitApplication();
                // TODO Add the other event handlers here
        public static void main(String[] arguments) {
            Message messageFrame = new Message();
            messageFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }If you have any questions, please let me know, as there are a number of new areas introduced that you may not have come across before.

  • Need help with calculator project for an assignment...

    Hi all, I please need help with my calculator project that I have to do for an assignment.
    Here is the project's specifications that I need to do"
    """Create a console calculator applicaion that:
    * Takes one command line argument: your name and surname. When the
    program starts, display the date and time with a welcome message for the
    user.
    * Display all the available options to the user. Your calculator must include
    the arithmetic operations as well as at least five scientific operations of the
    Math class.
    -Your program must also have the ability to round a number and
    truncate it.
    -When you multiply by 2, you should not use the '*' operator to perform the
    operation.
    -Your program must also be able to reverse the sign of a number.
    * Include sufficient error checking in your program to ensure that the user
    only enters valid input. Make use of the String; Character, and other
    wrapper classes to help you.
    * Your program must be able to do conversions between decimal, octal and
    hex numbers.
    * Make use of a menu. You should give the user the option to end the
    program when entering a certain option.
    * When the program exits, display a message for the user, stating the
    current time, and calculate and display how long the user used your
    program.
    * Make use of helper classes where possible.
    * Use the SDK to run your program."""
    When the program starts, it asks the user for his/her name and surname. I got the program to ask the user again and again for his/her name and surname
    when he/she doesn't insert anything or just press 'enter', but if the user enters a number for the name and surname part, the program continues.
    Now my question is this: How can I restrict the user to only enter 'letters' (and spaces of course) but allow NO numbers for his/her surname??
    Here is the programs code that I've written so far:
    {code}
    import java.io.*;
    import java.util.*;
    import java.text.*;
    public class Project {
         private static String nameSurname = "";     
         private static String num1 = null;
         private static String num2 = null;
         private static String choice1 = null;
         private static double answer = 0;
         private static String more;
         public double Add() {
              answer = (Double.parseDouble(num1) + Double.parseDouble(num2));
              return answer;
         public double Subtract() {
              answer = (Double.parseDouble(num1) - Double.parseDouble(num2));
              return answer;
         public double Multiply() {
              answer = (Double.parseDouble(num1) * Double.parseDouble(num2));
              return answer;
         public double Divide() {
              answer = (Double.parseDouble(num1) / Double.parseDouble(num2));
              return answer;
         public double Modulus() {
              answer = (Double.parseDouble(num1) % Double.parseDouble(num2));
              return answer;
         public double maximumValue() {
              answer = (Math.max(Double.parseDouble(num1), Double.parseDouble(num2)));
              return answer;
         public double minimumValue() {
              answer = (Math.min(Double.parseDouble(num1), Double.parseDouble(num2)));
              return answer;
         public double absoluteNumber1() {
              answer = (Math.abs(Double.parseDouble(num1)));
              return answer;
         public double absoluteNumber2() {
              answer = (Math.abs(Double.parseDouble(num2)));
              return answer;
         public double Squareroot1() {
              answer = (Math.sqrt(Double.parseDouble(num1)));
              return answer;
         public double Squareroot2() {
              answer = (Math.sqrt(Double.parseDouble(num2)));
              return answer;
         public static String octalEquivalent1() {
              int iNum1 = Integer.parseInt(num1);
    String octal1 = Integer.toOctalString(iNum1);
    return octal1;
         public static String octalEquivalent2() {
              int iNum2 = Integer.parseInt(num2);
              String octal2 = Integer.toOctalString(iNum2);
              return octal2;
         public static String hexadecimalEquivalent1() {
              int iNum1 = Integer.parseInt(num1);
              String hex1 = Integer.toHexString(iNum1);
              return hex1;
         public static String hexadecimalEquivalent2() {
              int iNum2 = Integer.parseInt(num2);
              String hex2 = Integer.toHexString(iNum2);
              return hex2;
         public double Round1() {
              answer = Math.round(Double.parseDouble(num1));
              return answer;
         public double Round2() {
              answer = Math.round(Double.parseDouble(num2));
              return answer;
              SimpleDateFormat format1 = new SimpleDateFormat("EEEE, dd MMMM yyyy");
         Date now = new Date();
         SimpleDateFormat format2 = new SimpleDateFormat("hh:mm a");
         static Date timeIn = new Date();
         public static long programRuntime() {
              Date timeInD = timeIn;
              long timeOutD = System.currentTimeMillis();
              long msec = timeOutD - timeInD.getTime();
              float timeHours = msec / 1000;
                   return (long) timeHours;
         DecimalFormat decimals = new DecimalFormat("#0.00");
         public String insertNameAndSurname() throws IOException{
              boolean inputCorrect = false;
                   while (inputCorrect == false) {
                        while (nameSurname == null || nameSurname.length() == 0) {
                             for (int i = 0; i < nameSurname.length(); i++) {
                             if ((nameSurname.charAt(i) > 'a') && (nameSurname.charAt(i) < 'Z')){
                                       inputCorrect = true;
                        else{
                        inputCorrect = false;
                        break;
                        try {
                             BufferedReader inStream = new BufferedReader (new InputStreamReader(System.in));
                             System.out.print("Please enter your name and surname: ");
                             nameSurname = inStream.readLine();
                             inputCorrect = true;
                        }catch (IOException ex) {
                             System.out.println("You did not enter your name and surname, " + nameSurname + " is not a name, please enter your name and surname :");
                             inputCorrect = false;
                        System.out.println("\nA warm welcome " + nameSurname + " ,todays date is: " + format1.format(now));
                        System.out.println("and the time is now exactly " + format2.format(timeIn) + ".");
                        return nameSurname;
              public String inputNumber1() throws IOException {
              boolean inputCorrect = false;
                   while (inputCorrect == false) {
                        try {
                             BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
                             System.out.print("\nPlease enter a number you want to do a calculation with and hit <ENTER>: ");
                             num1 = br.readLine();
                             double number1 = Double.parseDouble(num1);
                             System.out.println("\nThe number you have entered is: " + number1);
                             inputCorrect = true;
                        } catch (NumberFormatException nfe) {
                             System.out.println("\nYou did not enter a valid number: " + "\""+ num1 + "\" is not a number!!");
                             inputCorrect = false;
                        return num1;
         public String calculatorChoice() throws IOException {
              System.out.println("Please select an option of what you would like to do with this number from the menu below and hit <ENTER>: ");
              System.out.println("\n*********************************************");
              System.out.println("---------------------------------------------");
              System.out.println("Please select an option from the list below: ");
              System.out.println("---------------------------------------------");
              System.out.println("1 - Add");
              System.out.println("2 - Subtract");
              System.out.println("3 - Multiply");
              System.out.println("4 - Divide (remainder included)");
              System.out.println("5 - Maximum and minimum value of two numbers");
              System.out.println("6 - Squareroot");
              System.out.println("7 - Absolute value of numbers");
              System.out.println("8 - Octal and Hexadecimal equivalent of numbers");
              System.out.println("9 - Round numbers");
              System.out.println("0 - Exit program");
              System.out.println("**********************************************");
              boolean inputCorrect = false;
                   while (inputCorrect == false) {
                        try {
                             BufferedReader inStream = new BufferedReader (new InputStreamReader(System.in));
                             System.out.print("Please enter your option and hit <ENTER>: ");
                             choice1 = inStream.readLine();
                             int c1 = Integer.parseInt(choice1);
                             System.out.println("\nYou have entered choice number: " + c1);
                             inputCorrect = true;
                        } catch (NumberFormatException nfe) {
                             System.out.println("You did not enter a valid choice number: " + "\""+ choice1 + "\" is not in the list!!");
                             inputCorrect = false;
                        return choice1;
         public String inputNumber2() throws IOException {
              boolean inputCorrect = false;
                   while (inputCorrect == false) {
                        try {
                             BufferedReader br2 = new BufferedReader (new InputStreamReader(System.in));
                             System.out.print("\nPlease enter another number you want to do the calculation with and hit <ENTER>: ");
                             num2 = br2.readLine();
                             double n2 = Double.parseDouble(num2);
                             System.out.println("\nThe second number you have entered is: " + n2);
                             System.out.println("\nYour numbers are: " + num1 + " and " + num2);
                             inputCorrect = true;
                        } catch (NumberFormatException nfe) {
                             System.out.println("You did not enter a valid number: " + "\""+ num2 + "\" is not a number!!");
                             inputCorrect = false;
                        return num2;
         public int Calculator() {
              int choice2 = (int) Double.parseDouble(choice1);
              switch (choice2) {
                        case 1 :
                             Add();
                             System.out.print("The answer of " + num1 + " + " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 2 :
                             Subtract();
                             System.out.print("The answer of " + num1 + " - " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 3 :
                             Multiply();
                             System.out.print("The answer of " + num1 + " * " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 4 :
                             Divide();
                             System.out.print("The answer of " + num1 + " / " + num2 + " is: " + decimals.format(answer));
                             Modulus();
                             System.out.print(" and the remainder is " + decimals.format(answer));
                             break;
                        case 5 :
                             maximumValue();
                             System.out.println("The maximum number between the numbers " + num1 + " and " + num2 + " is: " + decimals.format(answer));
                             minimumValue();
                             System.out.println("The minimum number between the numbers " + num1 + " and " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 6 :
                             Squareroot1();
                             System.out.println("The squareroot of value " + num1 + " is: " + decimals.format(answer));
                             Squareroot2();
                             System.out.println("The squareroot of value " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 7 :
                             absoluteNumber1();
                             System.out.println("The absolute number of " + num1 + " is: " + decimals.format(answer));
                             absoluteNumber2();
                             System.out.println("The absolute number of " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 8 :
                             octalEquivalent1();
                             System.out.println("The octal equivalent of " + num1 + " is: " + octalEquivalent1());
                             octalEquivalent2();
                             System.out.println("The octal equivalent of " + num2 + " is: " + octalEquivalent2());
                             hexadecimalEquivalent1();
                             System.out.println("\nThe hexadecimal equivalent of " + num1 + " is: " + hexadecimalEquivalent1());
                             hexadecimalEquivalent2();
                             System.out.println("The hexadecimal equivalent of " + num2 + " is: " + hexadecimalEquivalent2());
                             break;
                        case 9 :
                             Round1();
                             System.out.println("The rounded number of " + num1 + " is: " + decimals.format(answer));
                             Round2();
                             System.out.println("The rounded number of " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 0 :
                             if (choice2 == 0) {
                                  System.exit(1);
                             break;
                   return choice2;
              public String anotherCalculation() throws IOException {
                   boolean inputCorrect = false;
                   while (inputCorrect == false) {
                             try {                              
                                  BufferedReader br3 = new BufferedReader (new InputStreamReader(System.in));
                                  System.out.print("\nWould you like to do another calculation? Y/N ");
                                  more = br3.readLine();
                                  String s1 = "y";
                                  String s2 = "Y";
                                  if (more.equals(s1) || more.equals(s2)) {
                                       inputCorrect = true;
                                       while (inputCorrect = true){
                                            inputNumber1();
                                            System.out.println("");
                                            calculatorChoice();
                                            System.out.println("");
                                            inputNumber2();
                                            System.out.println("");
                                            Calculator();
                                            System.out.println("");
                                            anotherCalculation();
                                            System.out.println("");
                                            inputCorrect = true;
                                  } else {
                                       System.out.println("\n" + nameSurname + " thank you for using this program, you have used this program for: " + decimals.format(programRuntime()) + " seconds");
                                       System.out.println("the program will now exit, Goodbye.");
                                       System.exit(0);
                             } catch (IOException ex){
                                  System.out.println("You did not enter a valid answer: " + "\""+ more + "\" is not in the list!!");
                                  inputCorrect = false;
              return more;
         public static void main(String[] args) throws IOException {
              Project p1 = new Project();
              p1.insertNameAndSurname();
              System.out.println("");
              p1.inputNumber1();
              System.out.println("");
              p1.calculatorChoice();
              System.out.println("");
              p1.inputNumber2();
              System.out.println("");
              p1.Calculator();
                   System.out.println("");
                   p1.anotherCalculation();
                   System.out.println("");
    {code}
    *Can you please run my code for yourself and have a look at how this program is constructed*
    *and give me ANY feedback on how I can better this code(program) or if I've done anything wrong from your point of view.*
    Your help will be much appreciated.
    Thanks in advance

    Smirre wrote:
    Now my question is this: How can I restrict the user to only enter 'letters' (and spaces of course) but allow NO numbers for his/her surname??You cannot restrict the user. It is a sad fact in programming that the worst bug always sits in front of the Computer.
    What you could do is checking the input string for numbers. If it contains numbers, just reprompt for the Name.
    AND you might want to ask yourself why the heck a calculator needs to know the users Name.

  • Need help with almost completed plugin engine project

    Hi all,
    For a while now I have been working on a plugin engine. After a few iterations, the engine is similar to the Eclipse engine, in that plugins use extension points and extensions to allow contributions. Unlike the eclipse engine I have added the ability for plugins to fire events through the engine and other plugins can add listeners, all through the plugin.xml manifest. Dependencies are mostly handled automatically at plugin load time (when extensions get resolved to extension points, and listeners get resolved to events). For the case where a plugin needs to use classes from another plugin, dependencies are also allowed to be declared. Like the eclipse engine, activation of plugins occurs the first time a class is used within the plugin's classpath, OR a plugin can be activated after it is loaded.
    What I need help with is testing, working on examples to provide with the engine project, and feedback/suggestions before we release the M1 build. I am asking for those that are interested in this type of work to volunteer to help where applicable and possible. I want to provide a solid plugin engine to the java community, one that is easy to use, works well, and is pretty effecient in terms of resource usage and performance.
    Of particular interest to me right at the moment is dealing with multiple versions. As I see it, the engine will be used within an application and as such plugins would be distributed with a specific application version. The plugin version itself is more of a notification as to what version a plugin is, although I imagine it will help when updating at runtime as well.
    Just a few other details of the engine. It handles (or will soon) dynamic load, unload and reload of plugins at runtime. Plugins can be distributed in an archive file format, we call .par (Plugin ARchive), with additional plugin filename extensions configurable at runtime. The plugins can be developed and deployed in an expanded directory format as they are in Eclipse as well, or in the archive format. In the archive format they do not need to be unzipped when deployed, and they can contain embeded jar/zip libraries. The engine handles finding and creating classes directly out of the .par file at runtime.
    Multiple locations to find plugins are configurable before the engine starts, and even after it starts more could be added to allow additional locations to find plugins. URLs are supported, and soon the HTTP protocol will be supported so that plugins can be downloaded and installed at runtime.
    The project can be found at www.sourceforge.net/projects/genpluginengine. If you would like to get involved and help out, please sign up on the dev mail list and send an email to introduce yourself to the rest of the members on the list.
    I'll also add that I am working on a Swing UI Framework built entirely from plugins. It provides a ready-to-launce UI application that developers can simply add their plugins to, extending various extension points of the framework to have menu items, toolbar buttons, status bar access, help and preferences dialog additions, file i/o choosers, tons of open-source components ready to use (or extend to add on to), and like Eclipse, hopefully... draggable window frames that can be dropped on any other frame to form a tabbed frame of windows. Some of this is a ways off, some is getting there now. Presently you can add menu items that do allow plugin activation when first clicked, so plugins can be loaded but not activated until needed. The Preference dialog works but is not completed, and a plugin that adds a plugin control panel to view all loaded plugins, activate them, load/unload/reload, view extension points, extensions, dependencies, etc is partially completed. The point is, to allow a ready to run UI framework in Swing with an easy path for developers to quickly build applications with. If you are interested in this, when you join the mail list and introduce yourself, indicate that you are interested in this as well, as we need help with plugin development for it and would appreciate more help here too.
    Look forward to some replies.

    Might I suggest setting up a project at a known project-site? I've seen your progress and questions posted here from time to time, but one of the drawbacks is that you have to fill each post with the entirity of your vision to explain what you're doing. That's a lot of text to read - and most folks will skip right over it.
    On the other hand, a well-crafted, good-looking project web-site, with appropriate links and docs and vision statements, diagrams, etc. will have more likelyhood of attracting volunteers. java.net and sourceforge.net are likely spots to set up shop. In addition, you get CVS and bug-tracking systems, which can be quite valuable in such a large-scale project where there are lots of pieces.

Maybe you are looking for

  • Using M1 and F1 ports in OTV set up

    I am building a typical OTV architecture (on a stick, not inline) on Nexus 7000s; the join and internal interfaces in my OTV VDC are using M1 card ports. Can the other end of those links -- i.e. the interfaces in my Agg VDC -- use ports on my F1 card

  • Problem in Depreciation Run.

    Hi Experts, During depreciation test run I am getting the below errors in error log. 1) Account 'Acc.dep. accnt.for ordinary depreciation' could not be found for area 20 2) Message(s) when structuring line items for document number ERROR00001      Me

  • Movement types for Stock in transit

    Hi, I want to know how to find out stock in transit for a particular plant using movement types.

  • "Oracle BPM  Suite 11g" and "Oracle SOA Suite 11g" components

    Dear Friends, I am very confusing about the "Oracle BPM suite 11g" and "Oracle SOA Suite 11g" and would like your help on explanation as the following : I have learn that In order to use "Oracle BPM Suite 11g" require to have "Oracle SOA Suite 11g" c

  • GR Printing

    Presently in MIGO I have printing option set as "individual slip", how to set to "Collective Slip"