用java做计算器指数xy怎样把y变上标在按钮上显示?

2024-11-15 01:43:34
推荐回答(3个)
回答1:

可以用EXP或X^Y,或者如下方法:
import javax.swing.*;
import java.awt.*;
class UP extends JFrame {
private static final Dimension minSize = new Dimension(300, 200);
private static final Dimension maxSize = new Dimension(1024, 768);
private static final Dimension preferredSize = new Dimension(600, 400);
public Dimension getMaximumSize() {return maxSize;}
public Dimension getMinimumSize() {return minSize;}
public Dimension getPreferredSize() {return preferredSize;}
public String getTitle() {return "Frame Title";}
UP() throws HeadlessException {
doLay();
attachListeners();
}
private void doLay() {
Container container = getContentPane();
//重点是这一句
container.add(new JButton("XY"),BorderLayout.NORTH);
pack();
}
private void attachListeners() {setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}
public static void main(String[] args) {new UP().setVisible(true);}
}

回答2:

换想法
写成
x^y

或者用xy

回答3:

通过value,text或者innerHTML试试。