Topic: 简单问题请教:程序运行后不能显示

  Print this page

1.简单问题请教:程序运行后不能显示 Copy to clipboard
Posted by: yxh520
Posted on: 2005-06-16 12:22

请教高手:此程序可编译,运行,但显示不出来。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class tianshi
{
public static void main(String[] args)
{
tsF frame = new tsF();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}

//A frame that contains a message panel
class tsF extends JFrame
{
public tsF()
{
setTitle("tianshi");

// add panel to frame
tsP panel = new tsP();
Container contentPane = getContentPane();
contentPane.add(panel);

// get screen dimensions
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;

// center frame in screen
setSize(screenWidth / 2, screenHeight / 2);
setLocation(screenWidth / 4, screenHeight / 4);

// set frame icon and title
Image img = kit.getImage("001.gif");
setIconImage(img);
}
}

/**
A panel that displays a message.
*/

class tsP extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponentPresent;

g.drawString("tianshi",
MESSAGE_X, MESSAGE_Y);
}

public static final int MESSAGE_X = 75;
public static final int MESSAGE_Y = 100;
}

2.Re:简单问题请教:程序运行后不能显示 [Re: yxh520] Copy to clipboard
Posted by: ysonic
Posted on: 2005-06-16 15:53

是不是要frame.setVisible(true)?

3.Re:简单问题请教:程序运行后不能显示 [Re: yxh520] Copy to clipboard
Posted by: yxh520
Posted on: 2005-06-16 16:38

谢谢拉!
不过已经有frame.show()啊
而且改了后还是不行。
有请路过的高手们帮个忙。
学生这里谢先。

4.Re:简单问题请教:程序运行后不能显示 [Re: yxh520] Copy to clipboard
Posted by: snowbird2005
Posted on: 2005-06-16 20:09

我运行了一下,可以显示呀。

5.Re:简单问题请教:程序运行后不能显示 [Re: yxh520] Copy to clipboard
Posted by: andys_king
Posted on: 2005-07-08 01:29

我似乎也可以


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923