case study

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 2635 Views - Last Post: 05 March 2011 - 02:02 PM Rate Topic: -----

#1 arnieaguirre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-March 11

case study

Posted 05 March 2011 - 04:51 AM

import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;


public class Case1 extends Frame implements ActionListener
{
    Font myf1 = new Font("Times New Roam", Font.BOLD, 14);
    TextField txtnmn,txtcode;
    Label lbl1, lbl2,lbl;
    Button btnEnter,btnNew;


    public Case1()
    {
        super("MERC Grocery");
        setLayout(new FlowLayout(70,20,20));
        //event handler for closing the frame
        addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });

        setSize(600,150);
        setLocation(100,50);
        setBackground(Color.lightGray);

        lbl1 = new Label("User Name ");
        add(lbl1);

        txtnmn = new TextField(10);
        add(txtnmn);

        lbl2 = new Label("Code ");
        add(lbl2);

        txtcode = new TextField(10);
        add(txtcode);

        lbl=new Label();
        add(lbl);

        btnEnter = new Button("Enter");
        add(btnEnter);
        btnEnter.addActionListener(this);


        btnNew = new Button("New Entry");
        add(btnNew);
        btnNew.addActionListener(this);
        setVisible(true);


         txtnmn.setEditable(true);
          txtcode.setEditable(true);
        setVisible(true);


    }

    public void actionPerformed(ActionEvent e)

    {
        String a="Kristine";
        String b="akosis";

        if( e.getSource() == btnEnter){



        if(a.equals(txtnmn.getText())&& b.equals(txtcode.getText()))

            JOptionPane.showMessageDialog(null, "Go");

        else
            JOptionPane.showMessageDialog(null, "Invalid");
        }

            if(e.getSource()==btnNew)
          {

              txtnmn.setText("");
              txtcode.setText("");
          }

    }
    public static void main (String [] args) {

        Case1 case1 = new Case1();

}
}

HI THIS IS MY PROGRAM....
I WILL ASK A QUESTION!
MY PROGRAM IS ABOUT A GROCERY CASE STUDY
I WILL ASK HOW CAN I CONNECT THE BUTTON ENTER AFTER I LOG IN THAT WILL APPEAR A NEW FRAME THAT HAVING A LIST OF A PRODUCT CODE??... TNX FOR THE HELP YOU MAY REPLY I REALLY APPRECIATE THE HELP YOU CAN GIVE..

This post has been edited by japanir: 05 March 2011 - 05:17 AM
Reason for edit:: Code tags added


Is This A Good Question/Topic? 0
  • +

Replies To: case study

#2 arnieaguirre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-March 11

Re: case study

Posted 05 March 2011 - 06:07 AM

hi japanir did you already reply in my post?., tnx.,
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10469
  • View blog
  • Posts: 38,809
  • Joined: 27-December 08

Re: case study

Posted 05 March 2011 - 07:05 AM

AWT is antiquated. Use the more modern Swing JComponents like JButton, JLabel, JTextField, etc., over Button, Label, TextField, etc.

I would design an Item class, and store a List<Item> or Item[]. Should be pretty easy to loop through and build a String if you simply want to use JOptionPane.

Also, once you get into designing multiple windows, etc., you will really need to separate your program state/data and user interface. I would design a StateManager or DataManager class to manage your Item[] or List<Item>, and have your GUI interact with that class.

I cover more on class design in my tutorial Moving Away From Parallel Arrays.
Was This Post Helpful? 0
  • +
  • -

#4 arnieaguirre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-March 11

Re: case study

Posted 05 March 2011 - 07:29 AM

View Postmacosxnerd101, on 05 March 2011 - 07:05 AM, said:

AWT is antiquated. Use the more modern Swing JComponents like JButton, JLabel, JTextField, etc., over Button, Label, TextField, etc.

I would design an Item class, and store a List<Item> or Item[]. Should be pretty easy to loop through and build a String if you simply want to use JOptionPane.

Also, once you get into designing multiple windows, etc., you will really need to separate your program state/data and user interface. I would design a StateManager or DataManager class to manage your Item[] or List<Item>, and have your GUI interact with that class.

I cover more on class design in my tutorial Moving Away From Parallel Arrays.


uhmm.. tnx 4 da reply., but in dat topic part of creating new frame my porf sed that not to use a JOptionPane.,can i ask favor to get a example program to you so i will have a idea.,
many many tnx
Was This Post Helpful? 0
  • +
  • -

#5 arnieaguirre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-March 11

Re: case study

Posted 05 March 2011 - 07:34 AM

we use a applet program sir.,
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10469
  • View blog
  • Posts: 38,809
  • Joined: 27-December 08

Re: case study

Posted 05 March 2011 - 07:41 AM

If you design a JFrame to display your Items, should be easy enough to instantiate a new MyFrame in your ActionListener.

I've outlined some logic and skeleton code. This should help you get started.
class DataManager{
      private List<Item> items;
 
     //manage access to the List
}

class MyFrame extends JFrame{
      //access DataManager to get the Items and display them
}

class Case1 extends JFrame implements ActionListener{
  
      public void actionPerformed(ActionEvent e){
          if(e.getSource() == newFrameButton)
              new MyFrame();
      }
}


Was This Post Helpful? 0
  • +
  • -

#7 arnieaguirre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-March 11

Re: case study

Posted 05 March 2011 - 07:47 AM

tnx 4 da effort to make a program that i request i will edit my program and follow ur example., it really be helpfull to finish my case study., i will post agen if i need a help... tnx
Was This Post Helpful? 0
  • +
  • -

#8 arnieaguirre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-March 11

Re: case study

Posted 05 March 2011 - 08:12 AM

View Postarnieaguirre, on 05 March 2011 - 07:47 AM, said:

tnx 4 da effort to make a program that i request i will edit my program and follow ur example., it really be helpfull to finish my case study., i will post agen if i need a help... tnx



hi agen sir., i already did the list and make a new frame but my new problem now after log in., then enter and after i click the pop up word "GO" how can the new frame will apppear?.., so i can see the list of a product that i encode?., tnx a lot
Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10469
  • View blog
  • Posts: 38,809
  • Joined: 27-December 08

Re: case study

Posted 05 March 2011 - 08:12 AM

Did you set the new JFrame as visible? See the JFrame setVisible(boolean) method.
Was This Post Helpful? 0
  • +
  • -

#10 arnieaguirre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-March 11

Re: case study

Posted 05 March 2011 - 08:30 AM

View Postmacosxnerd101, on 05 March 2011 - 08:12 AM, said:

Did you set the new JFrame as visible? See the JFrame setVisible(boolean) method.



there is a error only 1 error the erro in thr prgram is this part JFrame setVisible(boolean); the error says ;Expected
Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10469
  • View blog
  • Posts: 38,809
  • Joined: 27-December 08

Re: case study

Posted 05 March 2011 - 08:32 AM

You have to invoke the setVisible() method from the JFrame object.
myFrame.setVisible(true);


Was This Post Helpful? 0
  • +
  • -

#12 arnieaguirre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-March 11

Re: case study

Posted 05 March 2011 - 08:51 AM

import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;


public class Case1 extends JFrame implements ActionListener
{
    Font myf1 = new Font("Times New Roam", Font.BOLD, 14);
    TextField txtnmn,txtcode;
    Label lbl1, lbl2,lbl;
    Button btnEnter,btnNew;


    public Case1()
    {
        super("MERC Grocery");
        setLayout(new FlowLayout(70,20,20));
        //event handler for closing the frame
        addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });

        setSize(600,150);
        setLocation(100,50);
        setBackground(Color.lightGray);

        lbl1 = new Label("User Name ");
        add(lbl1);

        txtnmn = new TextField(10);
        add(txtnmn);

        lbl2 = new Label("Code ");
        add(lbl2);

        txtcode = new TextField(10);
        add(txtcode);

        lbl=new Label();
        add(lbl);

        btnEnter = new Button("Enter");
        add(btnEnter);
        btnEnter.addActionListener(this);


        btnNew = new Button("New Entry");
        add(btnNew);
        btnNew.addActionListener(this);
        setVisible(true);


         txtnmn.setEditable(true);
          txtcode.setEditable(true);
        setVisible(true);


    }

    public void actionPerformed(ActionEvent e)

    {
        String a="Kristine";
        String b="akosis";

        if( e.getSource() == btnEnter){



        if(a.equals(txtnmn.getText())&& b.equals(txtcode.getText()))

            JOptionPane.showMessageDialog(null, "Go");

        else
            JOptionPane.showMessageDialog(null, "Invalid");
        }

            if(e.getSource()==btnNew)
          {

              txtnmn.setText("");
              txtcode.setText("");
          }

    }
    public static void main (String [] args) {

        Case1 case1 = new Case1();
        class DataManager{
	      private List<Item> items;

	     //manage access to the List
	}

	class MyFrame extends JFrame{
	      //access DataManager to get the Items and display them
	      JFrame setVisible(boolean);
	      myFrame.setVisible(true);
	}

	class Case1 extends JFrame implements ActionListener{

	      public void actionPerformed(ActionEvent e){
	          if(e.getSource() == newFrameButton)
	              new MyFrame();
	               JFrame setVisible(boolean);
	      myFrame.setVisible(true);


	      }
	}


}
}





sir here's the code i already made., there's a error would you mind to fix it?., so i can move to a new steps that i needed., hmmm..sir i did not already put the product code in the list.,

Edited by macosxnerd101: Please, :code:.
Was This Post Helpful? 0
  • +
  • -

#13 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10469
  • View blog
  • Posts: 38,809
  • Joined: 27-December 08

Re: case study

Posted 05 March 2011 - 08:53 AM

You shouldn't be declaring all your classes in the main() method. It doesn't make sense to. The main() method should only be a few lines for unit testing, or to start the program.

Also, post the specific error message.
Was This Post Helpful? 0
  • +
  • -

#14 arnieaguirre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-March 11

Re: case study

Posted 05 March 2011 - 08:59 AM

<identifier> expected line 101
<identifier> expected line 101
')' expected line 102
';' expected line 110
Was This Post Helpful? 0
  • +
  • -

#15 arnieaguirre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-March 11

Re: case study

Posted 05 March 2011 - 09:09 AM

View Postmacosxnerd101, on 05 March 2011 - 08:53 AM, said:

You shouldn't be declaring all your classes in the main() method. It doesn't make sense to. The main() method should only be a few lines for unit testing, or to start the program.

Also, post the specific error message.


<identifier> expected line 101
<identifier> expected line 101
')' expected line 102
';' expected line 110
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2