• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to change JFrame size? can anyone see any other problems with this?

 
victoria donaghy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I added code tags to your post: always use them. Doesn't it look better I shall move the post to our GUIs forum

Unfortunately I can see some really poor design. You should probably get rid of addActionListener(this). One Listener per button, or if you use Java8 you can use a λ instead. The block of ifs is dreadful for maintenance. You have the numbers as fields of those buttons and you are not using those fields.
Using numbers to represent the actions you want to do is also pretty bad, I am afraid. You can simply use [i/] × y or similar. Or you can call a different method from each listener. But that should be in some different classes.
I can't see where you are changing sizes.
 
victoria donaghy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. Thanks for the advice.
As i am just a beginner this has been proven a difficult task.
How do i add one listener per button? not using java 8.
it is because i am not sure how to change the size of the jframe? If you could help me out that would be great thanks!!
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not sure how to change the size of the jframe?


I don't understand the question. You are currently using setSize(...). What else are you trying to do?

 
victoria donaghy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I go to run the program it comes up in a wee box in the corner? How am I able to change the size of it??
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posted code works fine for me.

If you need more help then post a proper SSCCE. That is, post demo code that simply creates a frame and sets the size. Prove to yourself that the setSize() method works and then see what is different from the SSCCE and your real code.
 
victoria donaghy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thats fine thanks so much for your help!
When you the run the program, did you notice that when selecting numbers and adding, multiplying etc together and then pressing equals it comes out as a double e.g 1 x 2 = 2.0
would you know how to change this to a full number??
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you call a setSize/setBounds or similar method on the Frame? You probably need to do that to make it appear other than very small. That needs to go before setVisible.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!