Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Action button HELP?

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Action button HELP?

    hi.. i want to add two button.. and chose one of them chart with by button...

     
    package chart_exapmles;
    import java.awt.BorderLayout;
    import java.awt.Color;
     
    import java.awt.GridLayout;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.data.category.CategoryDataset;
    public class single_chart extends JFrame {
     
    String bspr_mem ="";
    String bspr_cpu ="";
    String rtx_mem="";
    String rtx_cpu ="";
    public single_chart() {
    super("baslık");
    final JPanel girispanel_kuzey = new JPanel(new GridLayout(2,2,1,1));
    //final JPanel girispanel_guney = new JPanel(new GridLayout(1,2,1,1));
    //JPanel dugmepanel = new JPanel(new FlowLayout(FlowLayout.LEFT,2,2));
     
    double_list dd= new double_list();
    setBackground(Color.red);
    setForeground(Color.red);
     
     
    add(girispanel_kuzey);
    setSize(java.awt.Toolkit.getDefaultToolkit().getSc reenSize());
     
    /////////////////////////////////////////1.chart///////////////////////////////////////////
     
     
    CategoryDataset dataset_bspr_cpu =dd.createDataset_bspr();
    JFreeChart chart_bspr_cpu = dd.createChart(dataset_bspr_cpu,"lhssunp00 cpu");
    ChartPanel chartPanel_bspr_cpu = new ChartPanel(chart_bspr_cpu);
    chartPanel_bspr_cpu.setPreferredSize(new java.awt.Dimension(1400,700));
     
    ////////////////////2. chart //////////////////////////////////////////////////////////////////////
     
    CategoryDataset bspr_memory =dd.createDataset_bspr_memory();
    JFreeChart chart_bspr_memory = dd.createChart(bspr_memory,"lhssunp00 memory");
    ChartPanel chartPanel_bspr_memory = new ChartPanel(chart_bspr_memory);
    chartPanel_bspr_memory.setPreferredSize(new java.awt.Dimension(1400,700));
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    girispanel_kuzey.add(chartPanel_bspr_cpu);
    girispanel_kuzey.add(chartPanel_bspr_memory);
     
    setLocationRelativeTo(null);
    setEnabled(true);
    }
    }
    Last edited by utoptas; August 27th, 2010 at 03:46 AM.


  2. #2
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Action button HELP?

    Welcome to the forums! instead of using [code][/code] tags trying using [highlight=java][/highlight] tags. It preserves formatting and highlights your code, making it far easier to read.

    hi.. i want to add two button.. and chose one of them chart with by button...
    Your statement is a little vague. What problem('s) are you experiencing, are there any errors?

    If you don't know how to add a button then check this tutorial out: How to Use Buttons, Check Boxes, and Radio Buttons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    Last edited by Brt93yoda; August 27th, 2010 at 03:52 AM.

  3. #3
    Junior Member
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Action button HELP?

    there is no error... i want to add two button this code.. but when i tried to do ,chart doesn't shown... now can you add two button to choose graphics?

  4. #4
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Action button HELP?

    Quote Originally Posted by utoptas View Post
    there is no error... i want to add two button this code.. but when i tried to do ,chart doesn't shown... now can you add two button to choose graphics?
    Still not quite sure what you want. Do you want a button that changes what chart is displayed, two buttons?

  5. #5
    Junior Member
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Action button HELP?

    yes... you understand what i want to do..

  6. #6
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Action button HELP?

    I'm not exactly sure how to use those charts, but I'll give it a go with pseudo code.

     JButton button1 = new JButton("Show chart 1");
    button1.setActionCommand("chartOne");
     
    JButton button2 = new JButton("Show chart 2");
    button2.setActionCommand("chartTwo");
     
    button1.addActionListener(this);
    button2.addActionListener(this);
     
    add(button1);
    add(button2);
     
    public void actionPerformed(ActionEvent e) {
        if ("chartOne".equals(e.getActionCommand())) {
           //show chart 1
        } else {
          //show chart 2
        }
    }

    Like I said before, check out this link: How to Use Buttons, Check Boxes, and Radio Buttons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    Last edited by Brt93yoda; August 27th, 2010 at 04:43 AM.

  7. #7
    Junior Member
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Action button HELP?

    i update my code by using your example but is doesn't work...

    public class single_chart extends JFrame {
    private JButton b1 = new JButton("rtx"), b2 = new JButton("bspr");
        String bspr_mem ="";
        String bspr_cpu ="";
        String rtx_mem="";
        String rtx_cpu ="";
     
    public void actionPerformed(ActionEvent e) {
        if ("chartOne".equals(e.getActionCommand())) {
     
             double_list dd= new double_list();
          CategoryDataset dataset_rtx_cpu =dd.createDataset_rtx();
     
        JFreeChart chart_rtx_cpu = dd.createChart(dataset_rtx_cpu,"lhssunp01 cpu");
        ChartPanel chartPanel_rtx_cpu = new ChartPanel(chart_rtx_cpu);
        chartPanel_rtx_cpu.setPreferredSize(new java.awt.Dimension(1400,700));
          final JPanel girispanel_kuzey = new JPanel(new GridLayout(2,2,1,1));
          girispanel_kuzey.add(chartPanel_rtx_cpu);
           add(girispanel_kuzey);
        } else if("chartTwo".equals(e.getActionCommand())){
        double_list dd= new double_list();
        CategoryDataset dataset_bspr_cpu =dd.createDataset_bspr();
        JFreeChart chart_bspr_cpu = dd.createChart(dataset_bspr_cpu,"lhssunp00 cpu");
        ChartPanel chartPanel_bspr_cpu = new ChartPanel(chart_bspr_cpu);
        chartPanel_bspr_cpu.setPreferredSize(new java.awt.Dimension(1400,700));
          final JPanel girispanel_kuzey = new JPanel(new GridLayout(2,2,1,1));
          girispanel_kuzey.add(chartPanel_bspr_cpu);
           add(girispanel_kuzey);
     
        }
    }
     
     
        public single_chart() {
             super("baslık");
            JButton button1 = new JButton("Show chart 1");
    button1.setActionCommand("chartOne");
     
    JButton button2 = new JButton("Show chart 2");
    button2.setActionCommand("chartTwo");
     
    button1.addActionListener((ActionListener) this);
    button2.addActionListener((ActionListener) this);
       }
        }

  8. #8
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    490
    Thanks
    8
    Thanked 46 Times in 44 Posts

    Default Re: Action button HELP?

    CardLayout

    db

  9. #9
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    490
    Thanks
    8
    Thanked 46 Times in 44 Posts

    Default Re: Action button HELP?

    Cross posted
    New To Java - Action button HELP?

    db

Similar Threads

  1. ACTION LISTENER HANDLING
    By fari in forum What's Wrong With My Code?
    Replies: 19
    Last Post: June 12th, 2010, 08:31 PM
  2. Action Listener
    By Suzanne in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 29th, 2010, 10:50 AM
  3. Action from Radio Button
    By halfwaygone in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 25th, 2010, 10:52 AM
  4. Action Listener
    By kray66 in forum AWT / Java Swing
    Replies: 2
    Last Post: April 19th, 2010, 03:26 PM
  5. Need Help Action Listener....
    By vhizent23 in forum AWT / Java Swing
    Replies: 2
    Last Post: October 9th, 2009, 01:46 PM