本人Java刚入门小白一个
看到最近用代码做圣诞树挺火的我也来试试 ( •̀ ω •́ )✧
一个非常简易的圣诞树
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JLabel;
public class S {
public static void main(String[] args) {
JFrame a1 = new JFrame("圣诞树");
a1.setSize(600,600);
a1.setLocation(450,100);
a1.setLayout(null);
JPanel b2 = new JPanel();
b2.setBounds(280, 50, 20, 300);
b2.setBackground(Color.GREEN);
JPanel b3 = new JPanel();
b3.setBounds(90, 350, 400, 20);
b3.setBackground(Color.GREEN);
JPanel b4 = new JPanel();
b4.setBounds(110, 330, 360, 20);
b4.setBackground(Color.GREEN);
JPanel b5 = new JPanel();
b5.setBounds(130, 310, 320, 20);
b5.setBackground(Color.GREEN);
JPanel b6 = new JPanel();
b6.setBounds(150, 290, 280, 20);
b6.setBackground(Color.GREEN);
JPanel b7 = new JPanel();
b7.setBounds(130, 270, 320, 20);
b7.setBackground(Color.GREEN);
JPanel b8 = new JPanel();
b8.setBounds(150, 250, 280, 20);
b8.setBackground(Color.GREEN);
JPanel b9 = new JPanel();
b9.setBounds(170, 230, 240, 20);
b9.setBackground(Color.GREEN);
JPanel b10 = new JPanel();
b10.setBounds(190, 210, 200, 20);
b10.setBackground(Color.GREEN);
JPanel b11 = new JPanel();
b11.setBounds(170, 190, 240, 20);
b11.setBackground(Color.GREEN);
JPanel b12 = new JPanel();
b12.setBounds(190, 170, 200, 20);
b12.setBackground(Color.GREEN);
JPanel b13 = new JPanel();
b13.setBounds(210, 150, 160, 20);
b13.setBackground(Color.GREEN);
JPanel b14 = new JPanel();
b14.setBounds(230, 130, 120, 20);
b14.setBackground(Color.GREEN);
JPanel b15 = new JPanel();
b15.setBounds(210, 110, 160, 20);
b15.setBackground(Color.GREEN);
JPanel b16 = new JPanel();
b16.setBounds(230, 90, 120, 20);
b16.setBackground(Color.GREEN);
JPanel b17 = new JPanel();
b17.setBounds(250, 70, 80, 20);
b17.setBackground(Color.GREEN);
JPanel b18 = new JPanel();
b18.setBounds(270, 50, 40, 20);
b18.setBackground(Color.GREEN);
JPanel b19 = new JPanel();
b19.setBounds(240, 370, 100, 100);
b19.setBackground(Color.ORANGE);
JLabel c1 = new JLabel("圣");
c1.setForeground(Color.red);
c1.setBounds(280,100,280,50);
JLabel c2 = new JLabel("诞");
c2.setForeground(Color.red);
c2.setBounds(150,200,250,250);
JLabel c3 = new JLabel("快");
c3.setForeground(Color.red);
c3.setBounds(250,300,350,350);
JLabel c4 = new JLabel("乐");
c4.setForeground(Color.red);
c4.setBounds(350,400,450,450);
a1.add(b2);
a1.add(b3);
a1.add(b4);
a1.add(b5);
a1.add(b6);
a1.add(b7);
a1.add(b8);
a1.add(b9);
a1.add(b10);
a1.add(b11);
a1.add(b12);
a1.add(b13);
a1.add(b14);
a1.add(b15);
a1.add(b16);
a1.add(b17);
a1.add(b18);
a1.add(b19);
b2.add(c1);
b2.add(c2);
b2.add(c3);
b2.add(c4);
a1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
a1.setVisible(true);
}
}
圣诞树很丑,代码也很低级,大佬们别笑我`(*>﹏<*)′