我是菜鸟 刚开始学。
import javax.swing.*;
import java.awt.*;
public class HelloEclipse {
public static void main(String[] args) {
Myframe M1=new Myframe(100,200,Color.blue);
Myframe M2=new Myframe(200,200,Color.BLACK);
Myframe M3=new Myframe(300,200,Color.CYAN);
}}
class Myframe extends JFrame{
Myframe(int x,int y,Color color){
setBackground(color);
setLayout(new BorderLayout());
setLocation(400,200);
setSize(x,y);
setVisible(true);
}
}
发现这程序 颜色不管用。没有效果。为什么呢?怎么改呢?
import javax.swing.*;
import java.awt.*;
public class HelloEclipse {
public static void main(String[] args) {
Myframe M1=new Myframe(100,200,Color.blue);
Myframe M2=new Myframe(200,200,Color.BLACK);
Myframe M3=new Myframe(300,200,Color.CYAN);
}}
class Myframe extends JFrame{
Myframe(int x,int y,Color color){
setBackground(color);
setLayout(new BorderLayout());
setLocation(400,200);
setSize(x,y);
setVisible(true);
}
}
发现这程序 颜色不管用。没有效果。为什么呢?怎么改呢?
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;import javax.swing.JFrame;
public class HelloEclipse
{
public static void main(String[] args)
{
Myframe M1=new Myframe(100,200,Color.blue);
Myframe M2=new Myframe(200,200,Color.BLACK);
Myframe M3=new Myframe(300,200,Color.CYAN);
}
}
class Myframe extends JFrame
{
Myframe(int x,int y,Color color)
{
Container container = this.getContentPane();
container.setBackground(color);
setLayout(new BorderLayout());
setLocation(400,200);
setSize(x,y);
setVisible(true);
}
}