Jeremy said:
Actually, just tried the JLabel line you suggested, firstly importing the
"javax.swing.JLabel" class, and then :-
JLabel expression = new JLabel("x\u00B3 + 3x\u00b2 - 5");
How would I now display that? I've tried System.out.println(expression),
but it produces something weird.. Is this thing a graphics thing or
something?
Yes, when you wrote about "font ... available in java" I assumed you were
referring to GUI display of (a limited subset of) mathematical
expressions. JLabel is a Swing component used in graphical user interfaces
of the sort familiar to users of Microsoft Windows applications.
It isn't graphical in the sense of vector line/curve drawing approaches to
the rendering of mathematical expressions.
I can't think of any other interpretation of "font ... available in java"
but presumably there is. I look forward to finding out.
As ever, Andrew is right in saying the same string would work when output
to the console. The console may need to be configured to use an
appropriate font - In many locales the default font may be OK.
----------------------------------- 8< ---------------------------------
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
// GUI version using Java Swing
public class MathExpression {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new MathExpression();
}
});
}
MathExpression() {
JPanel p = new JPanel();
p.add(new JLabel("x\u00B3 + 3x\u00B2 - 5"));
JFrame f = new JFrame("MathExpression");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(p);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
----------------------------------- 8< ---------------------------------
// non-GUI console version
public class MathExpressionConsole {
public static void main(String[] args) {
System.out.println("x\u00B3 + 3x\u00B2 - 5");
}
}
----------------------------------- 8< ---------------------------------
Both the above work for me using Eclipse on Vista.
If you need to display more ambitious mathematical expressions, the
suggestions made by other responders will be more appropriate. In that
case the console is an inadequate medium.