• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

what i have done  RSS feed

Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have alredy post the guestion wth the title (how can i solve it )

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

public class KeyPad extends JPanel implements ActionListener{

private final static int NBUTTONS = 12;
private JButton buttons[];
private String labels[] = // An array of button labels
{ "1","2","3",

* KeyPad() constructor creates the keypad and sets this.kpc
* as a reference to its client.
public KeyPad(KeyPadClient kpc) {
this.kpc = kpc;
buttons = new JButton[NBUTTONS]; // Create the array itself
setLayout( new GridLayout(4,3));
for(int k = 0; k < buttons.length; k++) { // For each button
buttons[k] = new JButton(labels[k]); // Create a labeled button
buttons[k].addActionListener(this); // and a listener
add(buttons[k]); // and add it to the panel
} // for


public void actionPerformed(ActionEvent e) {
String keylabel = ((JButton)e.getSource()).getText();

the second class is

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

public class Calculator extends JFrame implements ActionListener{

int arr[] = new int[10];
private JLabel number = new JLabel("Enter a number : ") ;
private JTextField input = new JTextField(10);
private JTextArea display = new JTextArea(10,10);

private JButton insert = new JButton("insert");
private JButton add = new JButton("+");
private JButton sub = new JButton("-");
private JButton mult = new JButton("*");
private JButton divi = new JButton("/");
private JButton equ = new JButton("=");
private KeyPad kpc = new KeyPad(this);

public Calculator() {
getContentPane().setLayout(new FlowLayout());
} // Converter()
public void keypressCallback(String s) {
if (s.equals("C"))
input.setText(""); // Clear the input
input.setText(input.getText() + s); // Type the key

public void actionPerformed( ActionEvent e ) {
String buttonLabel = ((JButton)e.getSource()).getText();

if (buttonLabel.equals("insert")) {
displayOriginal.append(input.getText()+" ");


if (buttonLabel.equals("+")) {
display.append(" "+"+"+" " );



public static void main(String args[]) {
Calculator f = new Calculator();
f.setSize(300, 400);

} // main()


but its doesnt work with me
Posts: 9526
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Paul mentioned in your previous post, the more specific your question is, the more likely it is that you will get help. "It doesn't work for me" is not specific. What are you trying to accomplish and what is not working? Does it compile? Does it not work as expected?
It is obvious that you are working on a homework assignment and you won't learn anything if we hand you the answer. Do your part and we'll help you along.
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, it will help a lot if you keep related questions in the same thread. That way other people can catch up on the discussion so far and jump into the conversation. So please use a single thread to post updates and additional questions to a related project.

Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And please use the CODE UBB tags to enclose code. Doing so will make reading your code much easier.
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!