Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

AWT simple questions

Thread view: 
Thomas - 01 Aug 2007 21:57 GMT
Hello, I am writing a simple calculator in AWT/java and I have question
regarding it. I have to put around the buttons on container/palete in nice
way. Don't know how to do it, I looked throught the api, but I am looing for
the simplest way. Best wishes, Thomas.
Mark Space - 01 Aug 2007 22:08 GMT
> Hello, I am writing a simple calculator in AWT/java and I have question
> regarding it. I have to put around the buttons on container/palete in nice
> way. Don't know how to do it, I looked throught the api, but I am looing for
> the simplest way. Best wishes, Thomas.

The simplest way is definitely to use Swing and Matisse.

http://java.sun.com/docs/books/tutorial/uiswing/learn/index.html

and

http://java.sun.com/docs/books/tutorial/uiswing/

Now if this is an assignment where you cannot use Matisse or Swing,
please post up a short compilable example of what you have and I'm sure
someone will give you some advice on it.
Andrew Thompson - 02 Aug 2007 01:47 GMT
>Hello, I am writing a simple calculator in AWT/java and I have question
>regarding it. I have to put around the buttons on container/palete in nice
>way. Don't know how to do it, I looked throught the api, ..

You need to be going through the layout tutorial.
<http://www.google.com/search?q=java+tutorial+layout>

>..but I am looing for
>the simplest way.

Here is the simplest way to layout a calculator
keypad..

<sscce>
import java.awt.*;

class CalculatorKeypad extends Panel {

 String[] num = {
   "7","8","9","/",
   "4","5","6","*",
   "1","2","3","-",
   "0",".","=","+",
 };

 public CalculatorKeypad() {
   
   // adjust spacing (last two numbers) to suit need..
   super(new GridLayout(4,0,5,5));

   Button b;
   for (int ii=0; ii<num.length; ii++) {
     b = new Button(num[ii]);
     add(b);
   }
 }

 public static void main(String[] args) {
   Frame f = new Frame("Calculator");
   f.setLayout( new BorderLayout(5,5) );

   CalculatorKeypad ck = new CalculatorKeypad();
   f.add( ck, BorderLayout.CENTER );

   Label output = new Label("Result goes here..");
   output.setBackground(Color.black);
   output.setForeground(Color.white);
   f.add( output, BorderLayout.NORTH );

   f.pack();

   f.setVisible(true);
 }
}
</sscce>

Note the layout is exactly the same for Swing
based components (JButton, JFrame, JPanel
and JLabel).  Most modern day projects would
be using Swing for these components.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Thomas - 02 Aug 2007 16:53 GMT
> >Hello, I am writing a simple calculator in AWT/java and I have question
> >regarding it. I have to put around the buttons on container/palete in nice
[quoted text clipped - 63 lines]
> Message posted via JavaKB.com
> http://www.javakb.com/Uwe/Forums.aspx/java-general/200708/1

Okay, now it works , thx !!!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.