View the step-by-step solution to:

Dear tutor, Using GUI interface, I'm trying to creat the calculator with no function. If I excute with below codes, I don't see the textfeild.

Dear tutor,
Using GUI interface, I'm trying to creat the calculator with no function.
If I excute with below codes, I don't see the textfeild. Textfield is supposed be at between "calculator" and JButtons. Is there any problem with my codes?
====================================================
import java.awt.*;
import javax.swing.*;
public class Calculator{
public static void main(String[] args){
JFrame frm=new JFrame("Calculator");



Container contentPane=frm.getContentPane();
JLabel label=new JLabel("This is a calculator",SwingConstants.CENTER);
contentPane.add(label, BorderLayout.NORTH);
//Text field
JPanel centerpanel=new JPanel(new FlowLayout());
centerpanel.add(new JTextField());
frm.add(centerpanel, BorderLayout.CENTER);

JPanel panel=new JPanel();
contentPane.add(panel);

GridLayout layout=new GridLayout(5,4,5,5);
panel.setLayout(layout);

panel.add(new JButton("C"));
panel.add(new JButton("CE"));
panel.add(new JButton("+/-"));
panel.add(new JButton("/"));
panel.add(new JButton("7"));
panel.add(new JButton("8"));
panel.add(new JButton("9"));
panel.add(new JButton("*"));
panel.add(new JButton("4"));
panel.add(new JButton("5"));
panel.add(new JButton("6"));
panel.add(new JButton("-"));
panel.add(new JButton("1"));
panel.add(new JButton("2"));
panel.add(new JButton("3"));
panel.add(new JButton("+"));
panel.add(new JButton("0"));
panel.add(new JButton(""));
panel.add(new JButton("."));
panel.add(new JButton("="));
frm.add(panel, BorderLayout.SOUTH);

frm.pack();
frm.setSize(250,200);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setVisible(true);
}
}
Sign up to view the entire interaction

Top Answer

Dear Student, I assessed your homework question, but unfortunately was not able to complete... View the full answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online