473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Why output is not appear when I run simulation? I need help thanks in advance.

Expand|Select|Wrap|Line Numbers
  1. package tempconv;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7.  
  8. public class TempConv extends JFrame
  9. {
  10.  
  11. private JLabel CelL, FahrL;
  12. private JTextField CelTF, FahrTF;
  13. private CelsiusHandler cHandler;
  14. private FahrenheitHandler fHandler;
  15.  
  16. private static final double FTOC = 5.0 / 9.0;
  17. private static final double CTOF = 9.0 / 5.0;
  18. private static final int OFFSET = 32;
  19.  
  20. private static final int WIDTH = 400;
  21. private static final int HEIGHT = 100;
  22.  
  23. public void TempConv() //constructor
  24. {
  25.     //set labels
  26.     CelL = new JLabel("Temp in Celsius: ", SwingConstants.RIGHT);
  27.     FahrL = new JLabel("Temp in Fahrenheit: ", SwingConstants.RIGHT);
  28.  
  29.     //set text field
  30.     cHandler = new CelsiusHandler();
  31.     CelTF = new JTextField(10);
  32.  
  33.     //declare action listener object of its class 
  34.     fHandler = new FahrenheitHandler();
  35.     FahrTF = new JTextField(10);
  36.  
  37.  
  38.     //set title for window    
  39.     setTitle("Temperature Conversion");
  40.  
  41.     //get the container
  42.     Container pane = getContentPane();
  43.  
  44.     //set layout 
  45.     pane.setLayout(new GridLayout(1, 4));        
  46.  
  47.     //Add info to window's content pane
  48.     pane.add(CelL);
  49.     pane.add(CelTF);
  50.     pane.add(FahrL);    
  51.     pane.add(FahrTF);                                       
  52.  
  53.     //register action listener
  54.     CelTF.addActionListener(cHandler); 
  55.     FahrTF.addActionListener(fHandler);   
  56.  
  57.     //set dimension
  58.     setSize(WIDTH, HEIGHT);
  59.     setVisible(true);                      
  60.     setDefaultCloseOperation(EXIT_ON_CLOSE);
  61.  
  62. }
  63.  
  64. private class CelsiusHandler implements ActionListener
  65. {
  66.     public void actionPerformed(ActionEvent e)
  67.     {
  68.         double celsius, fahrenheit;
  69.  
  70.         celsius = Double.parseDouble(CelTF.getText());
  71.  
  72.         fahrenheit = CTOF * celsius + OFFSET;
  73.  
  74.         FahrTF.setText(String.format("%.2f" + celsius));
  75.     }
  76. }
  77.  
  78. private class FahrenheitHandler implements ActionListener
  79. {
  80.     public void actionPerformed(ActionEvent e)
  81.     {
  82.         double celsius, fahrenheit;
  83.  
  84.         fahrenheit = Double.parseDouble(FahrTF.getText());
  85.  
  86.         celsius = FTOC * (fahrenheit -32);
  87.  
  88.         CelTF.setText(String.format("%.2f", +celsius));
  89.     }
  90. }
  91.  
  92.     public static void main(String[] args) 
  93.     {
  94.        TempConv outputTable = new TempConv();
  95.     }
  96.  
  97. }
  98.  
Dec 9 '13 #1
1 1071
r035198x
13,262 8TB
You wrote public void TempConv() //constructor which is not correct. A constructor should have no return type at all. Instead you have void which makes it just a normal method. Change it to just
Expand|Select|Wrap|Line Numbers
  1. public TempConv()
Dec 11 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Andrew Phillipo | last post by:
I have a layout which works perfectly. It is three column, the central column is width:auto; with margins and the columns are absolutely positioned at top:0px; left:0px; and top:0px;right:0px; ...
10
by: Tomás | last post by:
When you simply want to store a number, what integral type do you use? For instance, let's say we have the following in a Poker game: struct Card { enum Suit { Hearts, Diamonds, Spades, Clubs...
4
by: rdemyan via AccessMonster.com | last post by:
Lately I've been noticing that charts that are created in my application don't always appear. When they don't appear, it is a consistent nonappearance. But then if I close the app and reopen it,...
3
by: Marc | last post by:
Anyone know how to add a drop down menu to a button that will appear when you right click the mouse?
8
by: Randy Smith | last post by:
Hi, I now need to add MasterPages to a number of existing forms, but when I add the code for MasterPage, the MasterPage does NOT appear when it runs. Any thoughts? TIA, Randy Smith
2
by: alizabeth33 | last post by:
I want to make an image pop up when my text is clicked and I can not figure out how to do that. Instead of having a new page come up, I want just the image to pop up and I know you can do it through...
2
by: kentman89 | last post by:
I'm having my thesis on traffic simulation and my group and I decided to use VB 6.0 The problem now is that I'm really not good at programming and I'm quite new to VB. So the scenario is...
3
by: ladycyradis | last post by:
Hi, I'm new here and have a bit of a problem. I'm building a form in Access 2003 and have a piece of code I'm using to ensure that the correct values are saved in the table when each option is...
7
by: fuchsia555 | last post by:
hi how can i remove the dashed border that appear when clicking on sites's header button ? i think it's css issue any help please ?
1
by: shaydaz | last post by:
When my form is submitted, the information from my radio button textbox does not show up? I received the code from Bytes.com:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.