importjavax.swing.*;importjava.awt.Graphics;publicclassTestPaintComponentextendsJFrame{publicTestPaintComponent(){add(newNewLabel("Banner"));}publicstaticvoidmain(String[...
import javax.swing.*;
import java.awt.Graphics;
public class TestPaintComponent extends JFrame {
public TestPaintComponent() {
add(new NewLabel("Banner"));
}
public static void main(String[] args) {
TestPaintComponent frame = new TestPaintComponent();
frame.setTitle("TestPaintComponent");
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}
class NewLabel extends JLabel {
public NewLabel(String text) {
super(text);
}
protected void paintComponent(Graphics g) {
g.draw3DRect(10, 10, 100, 100, true);
super.paintComponent(g);
}
}
为什么我引用了g.draw3DRect(10, 10, 100, 100, true);但实际效果没有图形没有3d效果.请高手解答一下
展开