我想创建一个带有不同字体大小的
以下是代码的示例。
JPanel
,但不使用JLabels
。以下是代码的示例。
public class MyPanel extends JPanel{
public MyPanel(string title){
JFrame frame = new JFrame(title);
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public void paintComponent(Graphics graphics){
graphics.drawString("Some Text",100,100);
// Should decrease font size
graphics.drawString("Some Smaller Text",200,200);
// Should increase font size
graphics.drawString("Some Bigger Text",300,300);
}
}
paint (Graphics g)
几乎肯定应该是paintComponent (Graphics g)
。