完全菜鸟一个。麻烦各位帮忙看看,JFrmae启动后老是最小化,需要双击窗口最大化或者手动把窗口拖大才能看到里面的内容。多谢多谢!
代码如下:
public class Font1{
public static void main(String args[])
{
MyPanel win = new MyPanel();
JFrame jf = new JFrame("Font Demo");
jf.setContentPane(win);
jf.setVisible(true);
jf.setSize(300,380);
jf.pack();
}
}
class MyPanel extends JPanel{
Font f1 = new Font("Courier",Font.PLAIN,20);
Font f2 = new Font("TimesRoman",Font.BOLD,20);
Font f3 = new Font("Helvetica",Font.ITALIC,22);
public MyPanel()
{
this.setBackground(Color.red);
this.setSize(100,200);
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
setSize(240,280);
g.setFont(f1);
g.setColor(Color.blue);
g.drawString("Font1",150,90);
g.setColor(Color.yellow);
g.fillRect(40,80,100,100);
g.setFont(f2);
g.setColor(Color.green);
g.drawString("Font2",20,40);
g.setFont(f3);
g.setColor(Color.cyan);
g.drawString("Font3",30,140);
}
}
代码如下:
public class Font1{
public static void main(String args[])
{
MyPanel win = new MyPanel();
JFrame jf = new JFrame("Font Demo");
jf.setContentPane(win);
jf.setVisible(true);
jf.setSize(300,380);
jf.pack();
}
}
class MyPanel extends JPanel{
Font f1 = new Font("Courier",Font.PLAIN,20);
Font f2 = new Font("TimesRoman",Font.BOLD,20);
Font f3 = new Font("Helvetica",Font.ITALIC,22);
public MyPanel()
{
this.setBackground(Color.red);
this.setSize(100,200);
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
setSize(240,280);
g.setFont(f1);
g.setColor(Color.blue);
g.drawString("Font1",150,90);
g.setColor(Color.yellow);
g.fillRect(40,80,100,100);
g.setFont(f2);
g.setColor(Color.green);
g.drawString("Font2",20,40);
g.setFont(f3);
g.setColor(Color.cyan);
g.drawString("Font3",30,140);
}
}