2 Replies - 824 Views - Last Post: 14 December 2009 - 06:43 PM Rate Topic: -----

#1 shahinalammarufkhan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-December 09

java help

Post icon  Posted 14 December 2009 - 05:38 AM

[code] :wub:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class calcuu extends JFrame implements ActionListener
{

JMenuBar mb;
JMenu edit,view,help;
JMenuItem cop,ex,fs,about;
JTextField tf;
JButton b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15;
JPanel panel1,panel2,panel3;

calcuu()
{

mb= new JMenuBar();
setJMenuBar(mb);

edit= new JMenu("Edit");
cop= new JMenuItem("Copy");
ex= new JMenuItem("Exit");
edit.add(cop);
edit.addSeparator();
edit.add(ex);
mb.add(edit);

view= new JMenu("View");
fs= new JMenuItem("Full Screen");
view.add(fs);
mb.add(view);

help= new JMenu("Help");
about= new JMenuItem("About");
help.add(about);
mb.add(help);

cop.addActionListener(this);
ex.addActionListener(this);
fs.addActionListener(this);
about.addActionListener(this);



panel1= new JPanel();
panel1.setLayout(new BorderLayout());
tf= new JTextField(50);
tf.setHorizontalAlignment(JTextField.RIGHT);
tf.setBackground(Color.PINK);
panel1.add(tf,BorderLayout.NORTH);

panel2= new JPanel();
panel2.setLayout(new GridLayout(4,4, 4,4));
b0= new JButton("9");
b0.setBackground(Color.GREEN);
b1= new JButton("8");
b1.setBackground(Color.GREEN);
b2= new JButton("7");
b2.setBackground(Color.GREEN);
b3= new JButton("6");
b3.setBackground(Color.GREEN);
b4= new JButton("5");
b4.setBackground(Color.GREEN);
b5= new JButton("4");
b5.setBackground(Color.GREEN);
b6= new JButton("3");
b6.setBackground(Color.GREEN);
b7= new JButton("2");
b7.setBackground(Color.GREEN);
b8= new JButton("1");
b8.setBackground(Color.GREEN);
b9= new JButton("0");
b9.setBackground(Color.GREEN);
b10= new JButton(".");
b10.setBackground(Color.GREEN);
b11= new JButton("=");
b11.setBackground(Color.YELLOW);
panel2.add(b0);
panel2.add(b1);
panel2.add(b2);
panel2.add(b3);
panel2.add(b4);
panel2.add(b5);
panel2.add(b6);
panel2.add(b7);
panel2.add(b8);
panel2.add(b9);
panel2.add(b10);
panel2.add(b11);


panel3= new JPanel();
panel3.setLayout(new GridLayout(4,1));
b12= new JButton("+");
b12.setBackground(Color.RED);
b13= new JButton("-");
b13.setBackground(Color.RED);
b14= new JButton("*");
b14.setBackground(Color.RED);
b15= new JButton("/");
b15.setBackground(Color.RED);
panel3.add(b12);
panel3.add(b13);
panel3.add(b14);
panel3.add(b15);

setLayout(new BorderLayout());
add(panel1,BorderLayout.NORTH);
add(panel2,BorderLayout.CENTER);
add(panel3,BorderLayout.EAST);

setTitle("My 1st Calcualtor");
setSize(250,200);
setLocation(200,200);
setVisible(true);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}


public void actionPerformed(ActionEvent e)
{
if(e.getSource()== cop)
{
JOptionPane.showMessageDialog(null,"Do you want to copy?");
}
if(e.getSource()== ex)
{
JOptionPane.showMessageDialog(null,"Be sure to exit !!!");

}
if(e.getSource()== fs)
{
JOptionPane.showMessageDialog(null,"Show the full screen");
}
else if(e.getSource()== about)
{
JOptionPane.showMessageDialog(null,"Abou the Calculator");
}
}


public static void main (String[] args)
{
calcuu lator= new calcuu();
}
}



Is This A Good Question/Topic? 0
  • +

Replies To: java help

#2 EdwinNameless  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 128
  • View blog
  • Posts: 723
  • Joined: 15-October 09

Re: java help

Posted 14 December 2009 - 06:54 AM

My psychic powers tell me you want to put something in the actionPerformed method. Am I right?

(I you don't know if I'm right, then I'm right! :) )
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: java help

Posted 14 December 2009 - 06:43 PM

Wait till I found my sunglasses
and respect rule #5 of this forum that was showed to you when you posted
#5 Give your topic a descriptive title, NOT "Help" or "Plz Help Me" or "I'm a noob"
"Java help" is kind of useless in a forum dedicated to help people with Java problem
Fix your post title, your font, and I'll have a look to your code
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1