4个回答
展开全部
package com.txz1;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Txz {
public static void main(String[] args) {
JFrame frame = new JFrame("������1.0");//����
frame.setBounds(100, 20, 20 * 48 + 16, 14 * 48 + 38);//���ý���λ�úʹ�С
JPanel panel = new JPanel();//��壬�൱������
panel.setBackground(Color.red);//������ɫ
frame.setContentPane(panel);
panel.setLayout(null);//�Զ��壬���λ��
//�������
ImageIcon boxImg = new ImageIcon("box2.PNG");
JLabel box = new JLabel(boxImg);//��ǩ���൱������
panel.add(box);
box.setBounds(5 * 48, 3 * 48, 48, 48);
//��ӹ���
ImageIcon workerImg = new ImageIcon("workerDown2.png");
JLabel worker = new JLabel(workerImg);
panel.add(worker);
worker.setBounds(8 * 48, 8 * 48, 48, 48);
//����ϰ���
ImageIcon goalImg = new ImageIcon("goal2.png");
JLabel goal = new JLabel(goalImg);
panel.add(goal);
goal.setBounds(7 * 48, 6 * 48, 48, 48);
//���Χǽ
ImageIcon wallImg = new ImageIcon("wall2.PNG");
JLabel[] walls = new JLabel[100];
for (int i = 0; i < walls.length; i++) {
walls[i] = new JLabel(wallImg);
}
int index = 0;//������������ͳ��Χǽ����
for (int i = 0; i < 20; i++) {
panel.add(walls[index]);
walls[index].setBounds(i * 48, 0, 48, 48);
index++;
panel.add(walls[index]);
walls[index].setBounds(i * 48, 13 * 48, 48, 48);
index++;
}
for (int i = 0; i < 12; i++) {
panel.add(walls[index]);
walls[index].setBounds(0, (i + 1) * 48, 48, 48);
index++;
panel.add(walls[index]);
walls[index].setBounds(19 * 48, (i + 1) * 48, 48, 48);
index++;
}
for (int i = 0, j = 0; i < 5; i++, j += 2) {
panel.add(walls[index]);
walls[index].setBounds((i + 2) * 48, j * 48, 48, 48);
index++;
}
for (int i = 0, j = 10; i < 5; i++, j--) {
panel.add(walls[index]);
walls[index].setBounds((i + 12) * 48, j * 48, 48, 48);
index++;
}
//����Ϊ�ɼ��
frame.setVisible(true);
}
}
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Txz {
public static void main(String[] args) {
JFrame frame = new JFrame("������1.0");//����
frame.setBounds(100, 20, 20 * 48 + 16, 14 * 48 + 38);//���ý���λ�úʹ�С
JPanel panel = new JPanel();//��壬�൱������
panel.setBackground(Color.red);//������ɫ
frame.setContentPane(panel);
panel.setLayout(null);//�Զ��壬���λ��
//�������
ImageIcon boxImg = new ImageIcon("box2.PNG");
JLabel box = new JLabel(boxImg);//��ǩ���൱������
panel.add(box);
box.setBounds(5 * 48, 3 * 48, 48, 48);
//��ӹ���
ImageIcon workerImg = new ImageIcon("workerDown2.png");
JLabel worker = new JLabel(workerImg);
panel.add(worker);
worker.setBounds(8 * 48, 8 * 48, 48, 48);
//����ϰ���
ImageIcon goalImg = new ImageIcon("goal2.png");
JLabel goal = new JLabel(goalImg);
panel.add(goal);
goal.setBounds(7 * 48, 6 * 48, 48, 48);
//���Χǽ
ImageIcon wallImg = new ImageIcon("wall2.PNG");
JLabel[] walls = new JLabel[100];
for (int i = 0; i < walls.length; i++) {
walls[i] = new JLabel(wallImg);
}
int index = 0;//������������ͳ��Χǽ����
for (int i = 0; i < 20; i++) {
panel.add(walls[index]);
walls[index].setBounds(i * 48, 0, 48, 48);
index++;
panel.add(walls[index]);
walls[index].setBounds(i * 48, 13 * 48, 48, 48);
index++;
}
for (int i = 0; i < 12; i++) {
panel.add(walls[index]);
walls[index].setBounds(0, (i + 1) * 48, 48, 48);
index++;
panel.add(walls[index]);
walls[index].setBounds(19 * 48, (i + 1) * 48, 48, 48);
index++;
}
for (int i = 0, j = 0; i < 5; i++, j += 2) {
panel.add(walls[index]);
walls[index].setBounds((i + 2) * 48, j * 48, 48, 48);
index++;
}
for (int i = 0, j = 10; i < 5; i++, j--) {
panel.add(walls[index]);
walls[index].setBounds((i + 12) * 48, j * 48, 48, 48);
index++;
}
//����Ϊ�ɼ��
frame.setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询