求大神解救。。。
做一只蝴蝶 2015-12-19 06:17:51 import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class E16_13 extends JFrame
{
private int i = 0;
private JLabel jl;
public static void main(String[] args)
{
E16_13 frame = new E16_13();
frame.setTitle("E16_13");
frame.setSize(800,600);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public E16_13()
{
Timer timer = new Timer(1000, new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jl = new JLabel(new ImageIcon("image/slide" + i + ".jpg"));
add(jl);
i++;
i = i%25;
}
});
timer.start();
}
}
最大化的时候又能看到?求大神解答啊。纠结了好久了。。。
下面这个程序也是,在paintComponent里我放了个按钮但也是显示不出来,最大化的时候又突然出来了,还原,又多出来一个按钮。。。好奇怪啊。。。求大神带我飞。。我做你小弟
import javax.swing.*;
import java.awt.*;
public class E15_11 extends JFrame
{
public E15_11()
{
add(new NewPanel());
}
public static void main(String[] args)
{
E15_11 frame = new E15_11();
frame.setTitle("E15_11");
frame.setSize(900,900);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class NewPanel extends JPanel
{
public NewPanel()
{
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
int width = getWidth();
int height = getHeight();
g.drawLine(width/2,height, width/2, height/4);
int[] x1 = {width/2-3,width/2,width/2+3};
int[] y1 = {height/4+3,height/4,height/4+3};
g.drawPolyline(x1,y1,x1.length);
g.drawLine(20,height-50,width-50,height-50);
int[] x2 = {width-53,width-50,width-53};
int[] y2 = {height-53,height-50,height-47};
g.drawPolyline(x2,y2,x2.length);
int[] x3 = new int[301];
int[] y3 = new int[301];
for(int i = 0; i<301; i++)
{
x3[i] = width/2-150+i;
y3[i] = height-50-(int)(0.01*(150-i)*(150-i));
}
g.drawPolyline(x3,y3,x3.length);
add(new JButton("xuechong"));
}
}