Help needed new to Swing Programming

Hi,
I have Crated a JFrame (Frame1) with 4 textfields and a button (by name GetBarchart).
My question is i will enter some values in 4 textfields and press the GetBarchart button it should display a new JFrame( say Frame2 ) and a Barchart with values taken form the 4 textfields should be displyed.
NOTE: I should get the BarChart displayed in Frame2 , NOT in Frame1.
anyhelp is appeciated .
Thanks in advance

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.data.category.*;
import org.jfree.ui.*;
// Make a main window with a top-level menu: File
public class MainWindow extends JFrame {
    public MainWindow() {
        super("Menu System Test Window");
        setSize(500, 500);
        // make a top level File menu
        FileMenu fileMenu = new FileMenu(this);
        // make a menu bar for this frame
        // and add top level menus File and Menu
        JMenuBar mb = new JMenuBar();
        mb.add(fileMenu);
        setJMenuBar(mb);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                exit();
    public void exit() {
        setVisible(false); // hide the JFrame
        dispose(); // tell windowing system to free resources
        System.exit(0); // exit
    public static void main(String args[]) {
        MainWindow w = new MainWindow();
        w.setVisible(true);
    private static MainWindow w ;
    protected JTextField t1, t2, t3, t4;
    // Encapsulate the look and behavior of the File menu
    class FileMenu extends JMenu implements ActionListener {
        private MainWindow mw; // who owns us?
        private JMenuItem itmPE   = new JMenuItem("ProductEvaluation");
        private JMenuItem itmExit = new JMenuItem("Exit");
        public FileMenu(MainWindow main) {
            super("File");
            this.mw = main;
            this.itmPE.addActionListener(this);
            this.itmExit.addActionListener(this);
            this.add(this.itmPE);
            this.add(this.itmExit);
        // respond to the Exit menu choice
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == this.itmPE) {
                JFrame f1 = new JFrame("ProductMeasurementEvaluationTool");
                f1.setSize(1290,1290);
                f1.setLayout(null);
                t1 = new JTextField("0");
                t1.setBounds(230, 630, 50, 24);
                f1.add(t1);
                t2 = new JTextField("0");
                t2.setBounds(430, 630, 50, 24);
                f1.add(t2);
                t3 = new JTextField("0");
                t3.setBounds(630, 630, 50, 24);
                f1.add(t3);
                t4 = new JTextField("0");
                t4.setBounds(840, 630, 50, 24);
                f1.add(t4);
                JLabel l1 = new JLabel("Select the appropriate metrics for Measurement Process Evaluation");
                l1.setBounds(380, 50, 380, 20);
                f1.add(l1);
                JLabel l2 = new JLabel("Architecture Metrics");
                l2.setBounds(170, 100, 110, 20);
                f1.add(l2);
                JLabel l3 = new JLabel("RunTime Metrics");
                l3.setBounds(500, 100, 110, 20);
                f1.add(l3);
                JLabel l4 = new JLabel("Documentation Metrics");
                l4.setBounds(840, 100, 130, 20);
                f1.add(l4);
                JRadioButton rb1 = new JRadioButton("Componenent Metrics",false);
                rb1.setBounds(190, 140, 133, 20);
                f1.add(rb1);
                JRadioButton rb2 = new JRadioButton("Task Metrics",false);
                rb2.setBounds(540, 140, 95, 20);
                f1.add(rb2);
                JRadioButton rb3 = new JRadioButton("Manual Metrics",false);
                rb3.setBounds(870, 140, 108, 20);
                f1.add(rb3);
                JRadioButton rb4 = new JRadioButton("Configuration Metrics",false);
                rb4.setBounds(190, 270, 142, 20);
                f1.add(rb4);
                JRadioButton rb6 = new JRadioButton("DataHandling Metrics",false);
                rb6.setBounds(540, 270, 142, 20);
                f1.add(rb6);
                JRadioButton rb8 = new JRadioButton("Development Metrics",false);
                rb8.setBounds(870, 270, 141, 20);
                f1.add(rb8);
                JCheckBox  c10 = new JCheckBox("Size");
                c10.setBounds(220, 170, 49, 20);
                f1.add(c10);
                JCheckBox c11 = new JCheckBox("Structure");
                c11.setBounds(220, 190, 75, 20);
                f1.add(c11);
                JCheckBox c12 = new JCheckBox("Complexity");
                c12.setBounds(220, 210, 86, 20);
                f1.add(c12);
                JCheckBox c13 = new JCheckBox("Size");
                c13.setBounds(220, 300, 49, 20);
                f1.add(c13);
                JCheckBox c14 = new JCheckBox("Structure");
                c14.setBounds(220, 320, 75, 20);
                f1.add(c14);
                JCheckBox c15 = new JCheckBox("Complexity");
                c15.setBounds(220, 340, 86, 20);
                f1.add(c15);
                JCheckBox c19 = new JCheckBox("Size");
                c19.setBounds(580, 170, 49, 20);
                f1.add(c19);
                JCheckBox c20 = new JCheckBox("Structure");
                c20.setBounds(580, 190, 75, 20);
                f1.add(c20);
                JCheckBox c21 = new JCheckBox("Complexity");
                c21.setBounds(580, 210, 86, 20);
                f1.add(c21);
                JCheckBox c22 = new JCheckBox("Size");
                c22.setBounds(580, 300, 49, 20);
                f1.add(c22);
                JCheckBox c23 = new JCheckBox("Structure");
                c23.setBounds(580, 320, 75, 20);
                f1.add(c23);
                JCheckBox c24 = new JCheckBox("Complexity");
                c24.setBounds(580, 340, 86, 20);
                f1.add(c24);
                JCheckBox c28 = new JCheckBox("Size");
                c28.setBounds(920, 170, 49, 20);
                f1.add(c28);
                JCheckBox c29 = new JCheckBox("Structure");
                c29.setBounds(920, 190, 75, 20);
                f1.add(c29);
                JCheckBox c30 = new JCheckBox("Complexity");
                c30.setBounds(920, 210, 86, 20);
                f1.add(c30);
                JCheckBox c31 = new JCheckBox("Size");
                c31.setBounds(920, 300, 49, 20);
                f1.add(c31);
                JCheckBox c32 = new JCheckBox("Structure");
                c32.setBounds(920, 320, 75, 20);
                f1.add(c32);
                JCheckBox c33 = new JCheckBox("Complexity");
                c33.setBounds(920, 340, 86, 20);
                f1.add(c33);
                ActionListener action = new MyActionListener(f1, t1, t2,t3,t4);
                JButton b1  = new JButton("Button1");
                b1.setBounds(230, 600, 120, 24);
                b1.addActionListener(action);
                f1.add(b1);
                JButton b2  = new JButton("Button2");
                b2.setBounds(430, 600, 120, 24);
                b2.addActionListener(action);
                f1.add(b2);
                JButton b3  = new JButton("Button3");
                b3.setBounds(630, 600, 120, 24);
                b3.addActionListener(action);
                f1.add(b3);
                JButton b4  = new JButton("Button4");
                b4.setBounds(840, 600, 120, 24);
                b4.addActionListener(action);
                f1.add(b4);
                JButton b5  = new JButton("Generatechart");
                b5.setBounds(1040, 600, 120, 24);
                b5.setBounds(530, 660, 120, 24);//uhrand
                b5.addActionListener(action);
                f1.add(b5);
                f1.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {
                        System.exit(0);
                f1.setVisible(true);
            } else {
                mw.exit();}
    class MyActionListener implements ActionListener {
        private JFrame     f1;
        private JTextField t1;
        private JTextField t2;
        private JTextField t3;
        private JTextField t4;
        private  final DecimalFormat result = new DecimalFormat("0.0");
        public MyActionListener(JFrame f1, JTextField tf1, JTextField tf2,JTextField tf3,JTextField tf4) {
            this.f1 = f1;
            this.t1 = tf1;
            this.t2 = tf2;
            this.t3 = tf3;
            this.t4 = tf4;
        public void actionPerformed(ActionEvent e) {
            String s = e.getActionCommand();
            if (s.equals("Button1")) {
                Component[] components = this.f1.getContentPane().getComponents();
                int numOfCheckBoxes = 81;
                int numChecked = 0;
                for (int i = 0; i < components.length; i++)
                    if (components[i] instanceof JCheckBox)
                        if (((JCheckBox)components).isSelected())
numChecked++;
double ratio = ((double) numChecked / (double) numOfCheckBoxes)*100;
this.t1.setText(result.format(ratio) );
}else if (s.equals("Button2")) {
Component[] components = this.f1.getContentPane().getComponents();
int numOfCheckBoxes = 81;
int numChecked = 0;
for (int i = 0; i < components.length; i++)
if (components[i] instanceof JCheckBox)
if (((JCheckBox)components[i]).isSelected())
numChecked++;
double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+5);
this.t2.setText(result.format(ratio) );
}else if (s.equals("Button3")) {
Component[] components = this.f1.getContentPane().getComponents();
int numOfCheckBoxes = 81;
int numChecked = 0;
for (int i = 0; i < components.length; i++)
if (components[i] instanceof JCheckBox)
if (((JCheckBox)components[i]).isSelected())
numChecked++;
double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+10);
this.t3.setText(result.format(ratio) );
}else if (s.equals("Button4")) {
Component[] components = this.f1.getContentPane().getComponents();
int numOfCheckBoxes = 81;
int numChecked = 0;
for (int i = 0; i < components.length; i++)
if (components[i] instanceof JCheckBox)
if (((JCheckBox)components[i]).isSelected())
numChecked++;
double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+15);
this.t4.setText(result.format(ratio) );
}else if (s.equals("Generatechart")) {
Bar_Chart barChart = new Bar_Chart("Bar Chart", t1.getText(),t2.getText(),t3.getText(),t4.getText());
barChart.pack();
RefineryUtilities.centerFrameOnScreen(barChart);
barChart.setVisible(true);
class Bar_Chart extends JDialog {
String t1,t2,t3,t4;
public Bar_Chart(String title, String t1, String t2, String t3, String t4) {
this.t1=t1;
this.t2=t2;
this.t3=t3;
this.t4=t4;
setModal(true);
setTitle(title);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
CategoryDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart, false);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
private CategoryDataset createDataset() {
String series1 = "First";
String series2 = "Second";
String series3 = "Third";
String series4 = "Fourth";
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(Double.parseDouble(t1.replace(',','.')), series1, "");
dataset.addValue(Double.parseDouble(t2.replace(',','.')), series2, "");
dataset.addValue(Double.parseDouble(t3.replace(',','.')), series3, "");
dataset.addValue(Double.parseDouble(t4.replace(',','.')), series4, "");
return dataset;
private static JFreeChart createChart(CategoryDataset dataset) {
JFreeChart chart = ChartFactory.createBarChart(
"Bar Chart", // chart title
"Category", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips?
false // URLs?
return chart;

Similar Messages

  • Help needed, new to java programming

    hi,
    I have craeted a Frame with some check boxes and button called "button1".
    Can anyone tell me how can i count the number of CHECKED check boxes so that when i press the button1 in my code it should display the result as number of checked check boxes divided by total number of check boxes. It should display the result in a textfield here RESULT textfield in my code
    Thanks in advance ...i am sending the code i have written so far....
    public class Frame extends java.awt.Frame {
        /** Creates new form Frame */
        public Frame() {
            initComponents();
            setSize(600, 600);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            buttonGroup1 = new javax.swing.ButtonGroup();
            checkbox1 = new java.awt.Checkbox();
            checkbox2 = new java.awt.Checkbox();
            checkbox3 = new java.awt.Checkbox();
            button1 = new java.awt.Button();
            textField1 = new java.awt.TextField();
            setLayout(null);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            checkbox1.setLabel("checkbox1");
            add(checkbox1);
            checkbox1.setBounds(160, 50, 84, 20);
            checkbox2.setLabel("checkbox2");
            add(checkbox2);
            checkbox2.setBounds(160, 70, 84, 20);
            checkbox3.setLabel("checkbox3");
            add(checkbox3);
            checkbox3.setBounds(160, 90, 84, 20);
            button1.setLabel("button1");
            button1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    button1ActionPerformed(evt);
            add(button1);
            button1.setBounds(150, 180, 57, 24);
            textField1.setText("Result");
            textField1.setName("Result");
            add(textField1);
            textField1.setBounds(260, 180, 44, 20);
            pack();
        private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
            // Add your handling code here:
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new Frame().show();
        // Variables declaration - do not modify
        private java.awt.Button button1;
        private javax.swing.ButtonGroup buttonGroup1;
        private java.awt.Checkbox checkbox1;
        private java.awt.Checkbox checkbox2;
        private java.awt.Checkbox checkbox3;
        private java.awt.TextField textField1;
        // End of variables declaration
    }

    Two problems in the code you repost-ed:
    1. It lacks import statements.
    2. There is an extraneous } at the end of the button1ActionPerformed method.
    Correct them and it'll work fine. Posting the full source code:
    import java.awt.Component;
    import java.awt.Checkbox;
    public class Frame extends java.awt.Frame
         /** Creates new form Frame */
         public Frame()
              initComponents();
          * This method is called from within the constructor to initialize the form.
          * WARNING: Do NOT modify this code. The content of this method is always
          * regenerated by the Form Editor.
         private void initComponents()
              checkbox1 = new java.awt.Checkbox();
              checkbox2 = new java.awt.Checkbox();
              checkbox3 = new java.awt.Checkbox();
              button1 = new java.awt.Button();
              textField1 = new java.awt.TextField();
              setLayout( null );
              addWindowListener( new java.awt.event.WindowAdapter()
                   public void windowClosing( java.awt.event.WindowEvent evt )
                        exitForm( evt );
              checkbox1.setLabel( "checkbox1" );
              add( checkbox1 );
              checkbox1.setBounds( 120, 40, 84, 20 );
              checkbox2.setLabel( "checkbox2" );
              add( checkbox2 );
              checkbox2.setBounds( 120, 60, 84, 20 );
              checkbox3.setLabel( "checkbox3" );
              add( checkbox3 );
              checkbox3.setBounds( 120, 80, 84, 20 );
              button1.setLabel( "button1" );
              button1.addActionListener( new java.awt.event.ActionListener()
                   public void actionPerformed( java.awt.event.ActionEvent evt )
                        button1ActionPerformed( evt );
              add( button1 );
              button1.setBounds( 50, 170, 57, 24 );
              textField1.setText( "textField1" );
              add( textField1 );
              textField1.setBounds( 240, 170, 60, 20 );
              pack();
         private void button1ActionPerformed( java.awt.event.ActionEvent evt )
              // Add your handling code here:
              Component[] components = getComponents();
              int numOfCheckBoxes = 0;
              int numChecked = 0;
              for ( int i = 0; i < components.length; i++ )
                   if ( components[i] instanceof Checkbox )
                        numOfCheckBoxes++;
                        Checkbox checkBox = (Checkbox) components;
                        if ( checkBox.getState() )
                             numChecked++;
              double ratio = (double) numChecked / (double) numOfCheckBoxes;
              textField1.setText( Double.toString( ratio ) );
         /** Exit the Application */
         private void exitForm( java.awt.event.WindowEvent evt )
              System.exit( 0 );
         * @param args the command line arguments
         public static void main( String args[] )
              new Frame().show();
         // Variables declaration - do not modify
         private java.awt.Button button1;
         private java.awt.Checkbox checkbox1;
         private java.awt.Checkbox checkbox2;
         private java.awt.Checkbox checkbox3;
         private java.awt.TextField textField1;
         // End of variables declaration
    I can see from the code that the GUI was generated by a tool. Since you're new to Java programming, I'd recommend ditching the tool and writing everything by hand, otherwise you're not learning much. It's just like when you're learning proofs in Maths, where you start with first principles before making use of the proofs on their own.
    Also, it'll help tremendously if you could spend some time going through the Java Tutorial (http://java.sun.com/docs/books/tutorial/). It's free, and I find it very useful.
    Hth.

  • Help needed new to swing

    Hi,
    First of all sorry if this particular post is in wrong forum but since my coding is done using swing and AWT i am posting this in swing forum.
    Coming to my question I have made a GUI ( Tool) using swing components and my complete java file is called as MainWindow.java .. and there is no problem with code its working fine.
    NOTE: I have taken help form 74philip, uhrand, dek dilirium, camkcir to generate this code..
    Nowmy question is i want to place my GUi in my university server so that i have to make a link and place in my university webpage so that when i click that link my program should get compiled and executed.
    How can i make a link ( say name that link as Measurement Tool) so that when i click that link my program should get Executed....?
    Thanks in advance

    example steps create a jar file that uses a few different files from an app created with NetBeans:
    C:\javalibs>jar cmf mymanifest.txt myapp.jar *.class myform.form
    example manifest file:
    Class-Path: lib/AbsoluteLayout.jar lib/commons-logging.jar lib/itext-1.02b.jar lib/jasperreports-0.6.4.jar lib/ojdbc14.jar
    Main-Class: MyForm
    If I remember correctly, the class-path isn't needed here when your using web start, just the main-class.
    example JNLP file:
    <?xml version="1.0" encoding="utf-8"?>
    <!-- JNLP File for Simple Application -->
    <jnlp
    codebase="http://net1/app/"
    href="app.jnlp">
    <information>
    <title>Data Entry</title>
    <vendor>Company Name</vendor>
    <description>DATA ENTRY</description>
    <description kind="short">DATA </description>
    <offline-allowed/>
    </information>
    <resources>
    <j2se version="1.5"/>
    <jar href="myapp.jar"/>
    </resources>
    <application-desc main-class="MyForm"/>
    </jnlp>
    Hope that helps,
    Alan

  • Urgent help needed - new to Macs, accidently cut and paste over top of photo folder and now no sign of folder or file, no auto back-up in place, how can I restore photos pls

    Urgent help needed - new to Macs, accidently cut and paste over top of photo folder and now no sign of folder or file, no auto back-up in place, how can I restore photos pls

    Thanks for prompt reply, yes we have tried that but have now closed down the browser we where the photos were.
    We haven't sent up time machine, do you know whether there is any roll-back function on a Mac?
    Thanks

  • Help needed in Logical Database Programming

    Hello Gurus,
    I am working on a Report on ASSET ACTIVITY BY DATE RANGE .
    The program is copied from std. program S_ALR_87011990.
    The above std. program displays for the whole financial year. This is modified for a particalar period range in the new leveraged program.
    My question is in the below code.
    We are fetching data using LDB ADA. The statement "GET anlcv" works fine here, I mean Sy-subrc is 0 and anlcv structure has some data in it.
    When it comes to statement "GET anepv" in the below code, we are not getting any data into that structure and sy-subrc NE 0. Then it is skipping all the get statements and directly going to statement " PERFORM abga_simulieren.".
    My logic lies in between this Get statement and the perform statement. When i see it in debugging mode my statement is not executed at all.
    What needs to be done. Please anyone help me.
    GET anlcv.
    CHECK select-options.
    MOVE anlcv TO sav_anlcv.
    GET anepv.
    CHECK select-options.
    Nur Bewegungen des Jahres des Berichtsdatums durchlassen.
    CHECK anepv-bzdat GE sav_gjbeg.
    CHECK anepv-bzdat IN so_bzdat. "Added for SIR-3132
    Bewegungen in SAV_ANEPV sammeln.
    MOVE anepv TO sav_anepv.
    APPEND sav_anepv.
    GET anlb LATE.
    Check auf Bestandskonto bei Gruppensummen erst hier, wegen
    fehlender Abgänge/Umbuchungen
    IF NOT summb IS INITIAL.
    IF NOT anlav-ktansw IN so_ktanw.
    REJECT 'ANLAV'.
    ENDIF.
    ENDIF.
    ANLCV aus Save-Area zurueckholen.
    CHECK NOT sav_anlcv-anln1 IS INITIAL.
    MOVE sav_anlcv TO anlcv.
    Abg-Simu: Abgang simulieren.
    PERFORM abga_simulieren.
    Promise to reward points
    Regards
    Mac

    1) delete line  CHECK anepv-bzdat ge sav_gjbeg.
    2) test with an asset , which has movements (purchases) in your intervall so_bzdat.
    otherwise post a movement (e.g. transaction type 100) with tcode abzon
    A.

  • Help needed with a paint program

    Hi, I am writing a program to work as a paint application. I have all the necessary buttons. One of my buttons needs to be able to add a small image to the painting frame by clicking the mouse onto the screen...for example, to display a picture of a house, I click the house button which then puts my house picture onto the scribble panel wherever I click the mouse. My problem is that I am new to java and I am stuck on how I can do this. I have put all the code on here which I have. If any one knows the code which I can add to make this work I would very much appreciate it as it is driving me insane!
    Many thanks....
    CODE "DrawingTools.java".............................
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.geom.*;
    public class DrawingTools {
    public static void main (String [] args) {
         Toolkit tk = Toolkit.getDefaultToolkit(); // get system dependent information
    Dimension dim = tk.getScreenSize(); // encapsulate width and height of system
    JFrame f = new DrawingToolFrame();
    f.setSize(800, 550);
    f.setTitle("Drawing Tool v1.10");
    f.setIconImage(tk.getImage("Paint.gif"));
    f.setVisible(true);
    f.setResizable(false);
    class DrawingToolFrame extends JFrame implements ActionListener {
    private JCheckBox checkNormal, checkBold, checkDotted, checkSpray;
    // private JRadioButton orBlack, orBlue, orRed, orYellow, orNormal, orBold, orDotted, orSpray;
    private JButton boldButton, dottedButton, sprayButton;
    private JButton blackButton, blueButton, yellowButton, redButton, greenButton, houseButton, tvButton, starButton;
    private ScribblePanel scribblePanel;
    private JButton scribbleButton, undoButton, newButton, quitButton;
    private JMenuItem newItem, quitItem, undoItem, houseItem, tvItem, starItem,/* normalItem,*/ boldItem, dottedItem, sprayItem, blackItem, blueItem, redItem, yellowItem, greenItem;
    public DrawingToolFrame() {
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    dispose();
    System.exit(0);
    Container contentPane = getContentPane();
    JMenuBar menuBar = new JMenuBar();
         setJMenuBar(menuBar);
         JMenu fileMenu = new JMenu("File");
         newItem = new JMenuItem("New");
         newItem.setMnemonic(KeyEvent.VK_N); //add Alt-N to New short-cut
         newItem.addActionListener(this);
         fileMenu.add(newItem);
         quitItem = new JMenuItem("Quit");
         quitItem.setMnemonic(KeyEvent.VK_Q); //add Alt-Q to Quit short-cut
         quitItem.addActionListener(this);
         fileMenu.add(quitItem);
         menuBar.add(fileMenu);
         JMenu editMenu = new JMenu("Edit");
         undoItem = new JMenuItem("Undo");
         undoItem.addActionListener(this);
         editMenu.add(undoItem);
         menuBar.add(editMenu);
         JMenu shapeMenu = new JMenu("Shape");
         houseItem = new JMenuItem("House");
         houseItem.addActionListener(this);
         shapeMenu.add(houseItem);
         tvItem = new JMenuItem("Television");
         tvItem.addActionListener(this);
         shapeMenu.add(tvItem);
         starItem = new JMenuItem("Star");
         starItem.addActionListener(this);
         shapeMenu.add(starItem);
         menuBar.add(shapeMenu);
    JMenu optionMenu = new JMenu("Option");
    JMenu lineMenu = new JMenu("Line");
         optionMenu.add(lineMenu);
              //normalItem = new JMenuItem("Normal");
              //normalItem.addActionListener(this);
              //lineMenu.add(normalItem);
              boldItem = new JMenuItem("Bold");
              boldItem.addActionListener(this);
              lineMenu.add(boldItem);
              dottedItem = new JMenuItem("Dotted");
              dottedItem.addActionListener(this);
         lineMenu.add(dottedItem);
         sprayItem = new JMenuItem("Spray");
         sprayItem.addActionListener(this);
         lineMenu.add(sprayItem);
         JMenu colourMenu = new JMenu("Colour");
         optionMenu.add(colourMenu);
              blackItem = new JMenuItem("Black");
              blackItem.addActionListener(this);
              colourMenu.add(blackItem);
              blueItem = new JMenuItem("Blue");
              blueItem.addActionListener(this);
              colourMenu.add(blueItem);
              redItem = new JMenuItem("Red");
              redItem.addActionListener(this);
         colourMenu.add(redItem);
         yellowItem = new JMenuItem("Yellow");
         yellowItem.addActionListener(this);
         colourMenu.add(yellowItem);
         greenItem = new JMenuItem("Green");
                   greenItem.addActionListener(this);
         colourMenu.add(greenItem);
         menuBar.add(optionMenu);
    JPanel p = new JPanel();
    ImageIcon scribbleIcon = new ImageIcon("Scribble.gif");
    scribbleButton = new JButton("Scribble", scribbleIcon);
    scribbleButton.setMnemonic(KeyEvent.VK_S); //add Alt-S to Undo short-cut
    scribbleButton.setToolTipText("Click this button and you can draw free hand lines.");
    p.add(scribbleButton);
    //scribbleButton = addJButton("Scribble", p);
    p.add(Box.createHorizontalStrut(20));
    ImageIcon undoIcon = new ImageIcon("Undo.gif");
    undoButton = new JButton("Undo", undoIcon);
    undoButton.setMnemonic(KeyEvent.VK_U); //add Alt-U to Undo short-cut
    undoButton.setToolTipText("Undo the last step");
    p.add(undoButton);
    //undoButton.addActionListener(this);
    p.add(Box.createHorizontalStrut(20));
    ImageIcon newIcon = new ImageIcon("New.gif");
    newButton = new JButton("New", newIcon);
    newButton.setMnemonic(KeyEvent.VK_N); //add Alt-N to New short-cut
    newButton.setToolTipText("Make a new Drawing");
    p.add(newButton);
    p.add(Box.createHorizontalStrut(20));
    ImageIcon quitIcon = new ImageIcon("Door.gif"); //add icon to button
    quitButton = new JButton("Quit", quitIcon);
    quitButton.setMnemonic(KeyEvent.VK_Q); //add Alt-Q to exit short-cut
    quitButton.setToolTipText("Click to Exit");
    p.add(quitButton);
    undoButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    scribblePanel.undo();}});
    scribbleButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    scribblePanel.repaint();}});
    newButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    scribblePanel.repaint();}});
    quitButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    System.exit(0);}});
    contentPane.add(p, "South");
    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(Box.createVerticalStrut(10));
    ImageIcon boldIcon = new ImageIcon("Bold.gif"); //add icon to button
    boldButton = new JButton("Bold", boldIcon);
    p.add(boldButton);
    p.add(Box.createVerticalStrut(10));
    ImageIcon dottedIcon = new ImageIcon("Dotted.gif"); //add icon to button
    dottedButton = new JButton("Dotted", dottedIcon);
    p.add(dottedButton);
    p.add(Box.createVerticalStrut(10));
    ImageIcon sprayIcon = new ImageIcon("Spray.gif"); //add icon to button
    sprayButton = new JButton("Spray", sprayIcon);
    p.add(sprayButton);
    /*     ButtonGroup groupA = new ButtonGroup();
         p.add(Box.createVerticalStrut(20));
         orNormal = addJRadioButton("Normal", true, groupA, p);
         p.add(Box.createVerticalStrut(20));
         orBold = addJRadioButton("Bold", false, groupA, p);
         p.add(Box.createVerticalStrut(20));
         orDotted = addJRadioButton("Dotted", false, groupA, p);
         p.add(Box.createVerticalStrut(20));
         orSpray = addJRadioButton("Spray", false, groupA, p);*/
    contentPane.add(p, "East");
    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(Box.createVerticalStrut(10));
    ImageIcon dIcon = new ImageIcon("Black.gif"); //add icon to button
    blackButton = new JButton("Black", dIcon);
    p.add(blackButton);
    p.add(Box.createVerticalStrut(10));
    ImageIcon eIcon = new ImageIcon("Blue.gif"); //add icon to button
    blueButton = new JButton("Blue", eIcon);
    p.add(blueButton);
    p.add(Box.createVerticalStrut(10));
    ImageIcon fIcon = new ImageIcon("Red.gif"); //add icon to button
    redButton = new JButton("Red", fIcon);
    p.add(redButton);
    p.add(Box.createVerticalStrut(10));
    ImageIcon gIcon = new ImageIcon("Yellow.gif"); //add icon to button
    yellowButton = new JButton("Yellow", gIcon);
    p.add(yellowButton);
    p.add(Box.createVerticalStrut(10));
    ImageIcon hIcon = new ImageIcon("Green.gif"); //add icon to button
    greenButton = new JButton("Green", hIcon);
    p.add(greenButton);
    p.add(Box.createVerticalStrut(30));
    ImageIcon houseIcon = new ImageIcon("house.gif");
    houseButton = new JButton("House", houseIcon);
    houseButton.setToolTipText("Click to add a house in the picture!");
    p.add(houseButton);
    //houseButton = addJButton("House", p);
    p.add(Box.createVerticalStrut(10));
    ImageIcon tvIcon = new ImageIcon("tv.gif");
    tvButton = new JButton("Television", tvIcon);
    tvButton.setToolTipText("Click to add a Television in the picture!");
    p.add(tvButton);
    //tvButton = addJButton("Television", p);
    p.add(Box.createVerticalStrut(10));
    ImageIcon starIcon = new ImageIcon("star.gif");
    starButton = new JButton("Star", starIcon);
    starButton.setToolTipText("Click to add stars in the picture!");
    p.add(starButton);
    //starButton = addJButton("Star", p);
    contentPane.add(p, "West");
    scribblePanel = new ScribblePanel();
    contentPane.add(scribblePanel, "Center");
    private JButton addJButton(String text, Container container) {
    JButton button = new JButton(text);
    container.add(button);
    return button;
    private JRadioButton addJRadioButton(String text, boolean on, ButtonGroup group, Container container) {
    JRadioButton button = new JRadioButton(text, on);
    group.add(button);
    container.add(button);
    return button;
    public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if (source instanceof JMenuItem) {
    String arg = e.getActionCommand();
    if (arg.equals("Undo"))
    scribblePanel.undo();
    else if (arg.equals("New"))
    scribblePanel.repaint();
    else if (arg.equals("Quit"))
    System.exit(0);
    }

    The code posted just sends any data it receives back to the person who sent it. To get it to work there, you probably should flush after the println. I believe your mother taught you always to flush. It seems you have forgotten.

  • Some help needed for shopping calculator program

    Hi. I would like to thank you in advance for helping me. At the moment I am pretty much stuck. I don't know how to add the input using 'while loop'. This is what I'm suppose to do:
    Write a program called ShoppingCalculator.java that allows the user to enter the prices of several items they have bought and then tells them the total amount. The user can enter the prices for as many items as they want, until they click Cancel. The program should then output the total amount they spent, in a message dialog box. Use pounds for all the amounts.
    So far I have written:
    import javax.swing.JOptionPane;
    public class ShoppingCalculator
        public static void main(String[] args)
                boolean done = false;
                double amount;
                String input;
                while (!done)
                        input = JOptionPane.showInputDialog("Enter the amount you spent on the next item:");
                        amount = Double.parseDouble (input);
                if (done = true)
                        JOptionPane.showMessageDialog (null, "You spent a total amound of £" + amount  );
    }Sorry if the code doesn't make much sense cause I've been changing the code around so many times that.
    At one point when I was playing around with the code, I manage to make the input dialog loop nicely but when I pressed cancel, the message dialog only output the last input I put in. What I'm really stuck here is I need to know how to add the input when using 'while loop' and is it correct to use the IF Statement on this program. Please give me some advice on how to and I will try to work on it again.

    Ok. I have edit the code and this is what it looks like:
    import javax.swing.JOptionPane;
    public class ShoppingCalculator
        public static void main(String[] args)
                boolean done = false;
                double amount;
                String input;
                double total = 0;
                while (!done)
                        input = JOptionPane.showInputDialog("Enter the amount you spent on the next item:");
                        amount = Double.parseDouble (input);
                            if (input == null)
                                        total = total + amount;
                                        JOptionPane.showMessageDialog (null, "You spent a total amound of " + total  );
    }I created another variable (total) and it even compiled. The only problem I have now is the message dialog wouldn't show at the end. When I press cancel and nothing happen. This is what I get on my output command window:
    Exception in thread "main" java.lang.NullPointerException
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:991)
    at java.lang.Double.parseDouble(Double.java:510)
    at ShoppingCalculator.main(ShoppingCalculator.java:23)
    Java Result: 1
    Anything that isn't right here?

  • Help need on ALV Report Program

    Hi all.....
    im facing problem in the following code....it shows 'No records found' (as same as my coding generated)whenever i give wrong vendor no:(lifnr), but if i gives the correct one(as in table lfa1)...it shows Runtime error as <b>"the occupied line length in the program text must not exceed the width of the internal table"</b>..
    pls verify...
    just go thru my code and revert me the feedback of what i did wrong and pls i dont want any example codes from u guys since i've seen so much and couldnt solve it with that...
    hope u understand......what i need
    Rewards based on the above reuirements....only
    *******************************CODING***********************************************
    REPORT ZALV_MERGE.
    TABLES:lfa1.
    DATA:BEGIN OF itab OCCURS 100,
    lifnr LIKE lfa1-lifnr,
    land1 LIKE lfa1-land1,
    name1 LIKE lfa1-name1,
    ort01 LIKE lfa1-ort01,
    regio LIKE lfa1-regio,
    sortl LIKE lfa1-sortl,
    END OF itab.
    data: i_repid like sy-repid,
          i_tabix like sy-tabix.
    TYPE-POOLS: slis.
    DATA: fcat TYPE slis_t_fieldcat_alv.
    SELECT-OPTIONS: LIFNR FOR LFA1-LIFNR.
    SELECT * FROM LFA1 INTO CORRESPONDING FIELDS OF TABLE itab WHERE lifnr IN LIFNR.
    clear i_tabix.
    describe table itab lines i_tabix.
    if i_tabix lt 1.
    write:/ 'No materials found'.
    exit.
    endif.
    i_repid = sy-repid.
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
       I_PROGRAM_NAME               = i_repid
       I_INTERNAL_TABNAME           = 'ITAB'
      I_STRUCTURE_NAME             =
      I_CLIENT_NEVER_DISPLAY       = 'X'
      I_INCLNAME                   = I_REPID
      I_BYPASSING_BUFFER           =
      I_BUFFER_ACTIVE              =
      CHANGING
        CT_FIELDCAT                  = fcat
      EXCEPTIONS
       INCONSISTENT_INTERFACE       = 1
       PROGRAM_ERROR                = 2
       OTHERS                       = 3.
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM             = i_repid
      I_CALLBACK_PF_STATUS_SET       = ' '
      I_CALLBACK_USER_COMMAND        = ' '
       I_STRUCTURE_NAME               = 'ITAB'
      IS_LAYOUT                      =
       IT_FIELDCAT                    = fcat
       I_SAVE                         = 'A'
      TABLES
        T_OUTTAB                       = ITAB
    EXCEPTIONS
       PROGRAM_ERROR                  = 1
       OTHERS                         = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    Hi,
    think inthis program in the function module REUSE_ALV_FIELDCATALOG_MERGE
    in exporting parameter you are using -->
    I_INTERNAL_TABNAME = <itab_name>
    this <itab_name> is not like any physical structure .So make a structure through SE11 like <itab_name>.
    u have to create a structure in SE11 with the fields, and then pass that structure into the REUSE_ALV_FIELDCATALOG_MERGE , in the parameter
    I_internal_tabname = ' structure name '.
    even though u create a structure, u need to pass it to the table parameter.
    then it will work.
    Otherwise manually build the fieldcatalog.
    find the following code as an example.
    DATA : l_pos TYPE i VALUE 1.
      ist_fieldcat-fieldname = 'POSID'.
      ist_fieldcat-tabname   = 'IT_FINAL'.
      ist_fieldcat-outputlen = 24.
      ist_fieldcat-col_pos   = l_pos.
    ist_fieldcat-ddictxt = 'L'.
      ist_fieldcat-key = 'X'.
      ist_fieldcat-seltext_l = 'Appropriation Request Number'.
      APPEND ist_fieldcat.
      CLEAR ist_fieldcat.
      l_pos = l_pos + 1.
      ist_fieldcat-fieldname = 'TXT04'.
      ist_fieldcat-tabname   = 'IT_FINAL'.
      ist_fieldcat-outputlen = 4.
      ist_fieldcat-col_pos   = l_pos.
      ist_fieldcat-ddictxt = 'L'.
    ist_fieldcat-key = 'X'.
      ist_fieldcat-seltext_l = 'Status'.
      ist_fieldcat-EMPHASIZE = 'C400'.
      APPEND ist_fieldcat.
      CLEAR ist_fieldcat.
      l_pos = l_pos + 1.
      ist_fieldcat-fieldname = 'UDATE'.
      ist_fieldcat-tabname   = 'IT_FINAL'.
      ist_fieldcat-outputlen = 8.
      ist_fieldcat-col_pos   = l_pos.
      ist_fieldcat-ddictxt = 'L'.
      ist_fieldcat-key = 'X'.
      ist_fieldcat-seltext_l = 'Status Date'.
    IST_FIELDCAT-EMPHASIZE = 'C600'.
      APPEND ist_fieldcat.
      CLEAR ist_fieldcat.
    <i><b>Reward point if find helpful
    Debjani</b></i>

  • HELP NEEDED: new ipod touch not working

    i just got an ipod touch for christmas
    i previosly had and ipod nano and so allready had itunes with music and pictures on.
    i plugged the ipod into the usb on the back of my laptop.
    a camera pop up appeared which i closed.
    my ipod touch is fully charged now.
    itunes is not recognising and it is not anywhere on the menu.
    the ipod touch itself will only show what i have been told is a register screen (wire pointing towards itunes logo)
    on "my computer" the ipod is only appearing under scanners and cameras
    please help as i just recieved it

    Hello and Welcome to Apple Discussions. 
    You need to download and install the latest version of iTunes:
    http://www.apple.com/itunes/download/
    Ambie12, You should probably start a new thread for your issue if downloading iTunes 7.5 doesn't help.
    Coolmaxx, have a read of this article:
    http://docs.info.apple.com/article.html?artnum=93716
    mrtotes

  • Help neede in changing standard program CN41

    Dear all,
    I am working on a requirement in PS module.
    The requirement is I need to copy the standard program RCNST000 of CN41 and I need to add some extra fields.
    Here in initial display project object, project object.
    when I select duration and Order cost plan 000 from the list It will display duration and order cost plan in the report.
    My requirement is when they select that I need to display cost per day and cost for currect month.
    Can anybody help me.
    Thnaks and regards
    Anil

    Dear all,
    I am working on a requirement in PS module.
    The requirement is I need to copy the standard program RCNST000 of CN41 and I need to add some extra fields.
    Here in initial display project object, project object.
    when I select duration and Order cost plan 000 from the list It will display duration and order cost plan in the report.
    My requirement is when they select that I need to display cost per day and cost for currect month.
    Can anybody help me.
    Thnaks and regards
    Anil

  • Help Needed on a java program

    I am very new to java and our teacher has given us a program
    that i am having quite a bit of trouble with. I was wondering if anyone could help me out.
    This is the program which i have bolded.
    {You will write a Java class to play the TicTacToe game. This program will have at least two data members, one for the status of the board and one to keep track of whose turn it is. All data members must be private. You will create a user interface that allows client code to play the game.
    The user interface must include:
    � Boolean xPlay(int num) which allows x to play in the square labeled by num. This function will return true if that play caused the game to end and false otherwise.
    � Boolean oPlay(int num) which allows o to play in the square labeled by num. This function will return true if that play caused the game to end and false otherwise.
    � Boolean isEmpty(int num) will check to see if the square labeled by num is empty.
    � Void display() which displays the current game status to the screen.
    � Char whoWon() which will return X, O, or C depending on the outcome of the game.
    � You must not allow the same player to play twice in a row. Should the client code attempt to, xPlay or oPlay should print an error and do nothing else.
    � Also calling whoWon when the game is not over should produce an error message and return a character other than X, O, or C.
    � Client code for the moment is up to you. Assume you have two human players that can enter the number of the square in which they want to play.
    Verifying user input WILL be done by the client code.}

    This is the program which i have bolded.Hmmm, that doesn't look like any programming language I've ever seen. I guess you have the wrong forum here, because it isn't Java.
    That looks like a natural-language programming language that directly understands a homework assignment. Either that, or you really did just post the assignment. You wouldn't have done that though, right?

  • IPhone 5s and iTunes Help Needed - NEW PC

    Hi, I got the iPhone 5s back in October (1st ever Apple product) and transfered my music and photos onto it via iTunes.
    What I need help with is as my laptop is in for repair (complete system restore) can I download  iTunes on mums laptop and put a few songs and pics on my iPhone WITHOUT clearing the  curent files and leaving me without nothing on it.
    Thanks
    James

    Use these instructions to open the library from its location on the external hard drive...
    How to open an alternate iTunes Library file or create a new one
    http://docs.info.apple.com/article.html?artnum=304447
    This assumes that everything needed for an iTunes library is on the external hard drive which includes the data base files that contain the info you are concerned about (playlists, counts, ratings, etc.).
    Patrick

  • Help needed with a chat program

    Hi everyone! i'm busy with a client/server chat program. I'm really stuck because i can't seem to get the messages from one client to show on the other client's screen.
    If one client sends a message to another client, the server receives the message, but the second client does not receive the message.
    Here is the server code that sends messages to the clients:
    BufferedReader incomeReader = null;
    PrintWriter outWriter = null;
    try {
         incomeReader = new BufferedReader(new InputStreamReader (incomingSocket.getInputStream()));
    outWriter = new PrintWriter(incomingSocket.getOutputStream(),true);
    }catch (Exception e) {
              System.out.println("error handling a client: " + e);
    System.exit(-1);
    line = incomeReader.readLine();
    textArea.append(line + "\n");               
    outWriter.println(line);
    The server is suppose to put the message it receives on the text area on the server screen, and then send the message to all clients connected to it.
    I hope somebody will be able to help me...

    The code posted just sends any data it receives back to the person who sent it. To get it to work there, you probably should flush after the println. I believe your mother taught you always to flush. It seems you have forgotten.

  • Help needed on a chat program..............

    Somebody please help me. I can't seem to get my client/server program to work well. The problem is that when a client sends a message to another client, the other client doesn't receive that message. Instead, the server and the client that sent the message are the ones that receive the message.
    Here is the server code that processes the messages:
    BufferedReader incomeReader = null;
    PrintWriter outWriter = null;
    try {
         incomeReader = new BufferedReader(new InputStreamReader(incomingSocket.getInputStream()));
    outWriter = new PrintWriter(incomingSocket.getOutputStream(),true);
    }catch (Exception e) {
              System.out.println("error handling a client: " + e);
    System.exit(-1);
    line = incomeReader.readLine();
    outWriter.println(line);
    outWriter.flush();
    Well, i hope somebody will be able to help....

    incomeReader = new BufferedReader(new InputStreamReader(incomingSocket.getInputStream()));
    outWriter = new PrintWriter(incomingSocket.getOutputStream(),true);Quite what you programmed. "incomingSocket" sends the message and gets it back.

  • Help needed to trace a program ...

    Hi,
    I am trying to reach the program which actually generates the PO from ME21N/ME22N. Could you please help me trace or let me know the program name ??
    Once PO is created and if I have the print option set in the "Messages", the PO is printed to the printer. I want to trace after the point, the PO is saved in the table. i.e. from the time PO output is assembled for printing. also i want to know if its in .txt format ??
    thanks

    Hi Rad Sha,
    your program should be run in background, if you want to look that, you have to activate the background debuging.
    To do that, start a ME22N/ME21N, put /hs (in the field for the transaction). Save your PO, that will go in debuging. Use the button Setting, select the background debugging and press save.
    After this you could press the key F8.
    You will have a new window that will appear, in debug mode. This window correspond of the background.
    Rgd
    Frédéric

Maybe you are looking for

  • How to create an applet in a jDesktopPane

    hello i would like to create an applet (JApplet) in a desktop (JDesktopPane). i have to put the applet in a JInternalFrame so i can move and resize the window around. indeed i can have several applets in the JDesktopPane. it would be more powerfull t

  • HP Advisor stops working on my Pavilion p6330f with Windows 7 Home Premium 64 bit system

    My computer is a  Pavilion p6330f  with Windows 7 Home Premium 64 bit system.  It bothers me when I get error messages and can't seem to correct the problem.  After loging onto my computer  a message comes on that the HP Advisor stopped working. When

  • SAP EP Error: Dispatcher running but no server connected!

    Hi Every body I tried to activate the debug remote, I access on configTool and on the section of process node I activate the options of debugabble, enable debugable , restricted load balancing. Then I apply the changes and restart the services and my

  • How do I create an executable file?

    How exactly do I create an executable file from my .java file?

  • Install linux 11.1.0.7

    Hi, I am sure that this has been addressed before and if so please post a link to the appropriate thread. I am trying to find 11.1.0.7 for 32 bit linux. I have 11.1.0.6 and am not sure if I need an install download or to apply patches to my 11.1.0.6