• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

float cannot be dereferenced

 
Erik Evertsen
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made my first JAVA program to try it out, but when I compile the source code I get the message: "C:\Documents and Settings\E. Evertsen\Bureaublad\Muziekcalculator.java:44: float cannot be dereferenced flsdtextfield.setText(stuitkomst);". What's the problem? Thanx allready.


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Muziekcalculator extends JFrame implements ActionListener{
protected JTextField cmbtextfield;
protected JTextField bfmtextfield;
protected JTextField sdtextfield;
float flcmbtextfield;
float flbfmtextfield;
float flsdtextfield;
float uitkomst;

public Muziekcalculator() {
super("Muziekcalculator");
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
Container mcpane = getContentPane();
FlowLayout mclayout = new FlowLayout();
JLabel cmblabel = new JLabel("Capaciteit MB: ", JLabel.LEFT);
JLabel bfmlabel = new JLabel("Bitfrequentie Muziek: ", JLabel.LEFT);
JLabel sdlabel = new JLabel("Speelduur: ", JLabel.LEFT);
cmbtextfield = new JTextField(4);
bfmtextfield = new JTextField(3);
sdtextfield = new JTextField(8);
sdtextfield.setEnabled(false);
mcpane.add(cmblabel);
mcpane.add(bfmlabel);
mcpane.add(sdlabel);
mcpane.add(cmbtextfield);
mcpane.add(bfmtextfield);
mcpane.add(sdtextfield);
cmbtextfield.addActionListener(this);
bfmtextfield.addActionListener(this);
}
public void actionPerformed(ActionEvent mcactionevent) {
String stcmbtextfield = cmbtextfield.getText();
String stbfmtextfield = bfmtextfield.getText();
flcmbtextfield = Float.parseFloat(stcmbtextfield);
flbfmtextfield = Float.parseFloat(stbfmtextfield);
uitkomst = flcmbtextfield * 1024 / (flbfmtextfield / 8);
String stuitkomst = Float.toString(uitkomst);
flsdtextfield.setText(stuitkomst);
}
}
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't call methods on float variables.
 
Krishnan Loganathan
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Erik,
you cannot call a method over primitive variables. Even though, it is Float means also, u can't call setXXXX methods. since, Float is a immutable class/object. I think so, u have to display the result in the form. so u can call the following st., instead of that one.

sdtextfield.setText(stuitkomst);

Regards,
Loga
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic