• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
mooooooo ..... tiny ad ....
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic