import java.awt.Graphics;
import javax.swing.*;
public class Fei extends JFrame{
private JLabel jLabel = new JLabel("bananer");
public Fei(){
add(jLabel);
System.out.println(jLabel.getGraphics());
}
public static void main(String[] args){
Fei frame = new Fei();
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Fei");
frame.setVisible(true);
JOptionPane.showMessageDialog(null, "123");/*这里为什么要加这句,
书上说延时作用,
不然看不到线,这里最根本的原因是什么
为什么去掉就看不到线
明明后两句画了线的*/
Graphics graphics = frame.jLabel.getGraphics();
graphics.drawLine(0, 0, 50, 50);
}
}
import javax.swing.*;
public class Fei extends JFrame{
private JLabel jLabel = new JLabel("bananer");
public Fei(){
add(jLabel);
System.out.println(jLabel.getGraphics());
}
public static void main(String[] args){
Fei frame = new Fei();
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Fei");
frame.setVisible(true);
JOptionPane.showMessageDialog(null, "123");/*这里为什么要加这句,
书上说延时作用,
不然看不到线,这里最根本的原因是什么
为什么去掉就看不到线
明明后两句画了线的*/
Graphics graphics = frame.jLabel.getGraphics();
graphics.drawLine(0, 0, 50, 50);
}
}
JOptionPane.showMessageDialog(null, "123");是用来弹出一个对话框,
showMessageDialog 方法是 弹出一个消息提示框,
JOptionPane 中也有用来弹出其他类型对话框的方法。
Object message)
throws HeadlessException Brings up an information-message dialog titled "Message".
http://topic.csdn.net/u/20080724/21/982EDCBF-4B1E-414C-AED2-C05B6DBB38FB.html#r_51257468