- Java
Java实现恶搞代码
- 2023-8-20 18:14:24 @
…… 懒得开头了,直接来罢! 文件:
- Java源程序:file
- res/1.jpg: file
- res/2.jpg: file
- res/3.jpg: file
- res/4.gif: file
记得把图片和Java代码放在同一个文件夹内!然后图片又都放在一个res文件夹内!!!
如图:
写了好久,累死了
//源代码
package myProject;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.wing.JButton;
import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Project {
public static void main(String[] args) {
Project.init();
}
public static void init() {
JFrame f = new JFrame("嘿嘿嘿");
f.setLocation(500,200);
f.setSize(300,200);
f.setLayout(null);
f.setResizable(false);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setUndecorated(true);
JLabel l = new JLabel("你是小黑子吗(doge");
JLabel l1 = new JLabel();
ImageIcon icon = new ImageIcon("res/1.jpg");
l1.setIcon(icon);
l.setBounds(120, 80, 200, 40);
l1.setBounds(0, 0, 300, 200);
l.setFone(new Font("宋体", Font.BOLD, 18));
f.add(l);
f.add(l1);
JButton j1 = new JButton("是");
JButton j2 = new JButton("不是");
JButton j3 = new JButton("关闭");
j1.setBounds(0, 160, 80, 40);
j2.setBounds(220, 160, 80, 40);
j3.setBounds(230, 0, 80, 40);
f.add(j1);
f.add(j2);
f.add(j3);
ProjectLister j = new ProjectLister(f, j1, j2, j3);
j1.addActionListener(j);
j2.addActionListener(j);
j3.addActionListener(j);
f.setVisible(true);
}
}
class ProjectLister implements ActionListener {
JFrame f;
JButton j1;
JButton j2;
JButton j3;
int k = 0;
int i = 0, j = 0;
Random rand = new Random();
public ProjectLister(JFrame f, JButton j1, JButton j2, JButton j3) {
this.f = f;
this.j1 = j1;
this.j2 = j2;
this.j3 = j3;
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == j1)
{
JOptionPane.showMessageDialog(f, "欢迎,小黑子!!!");
f.dispose();
i = rand.nextInt(1000);
j = rand.nextInt(500);
JFrame f1 = new JFrame("哈哈哈");
f1.setLocation(i, j);
f1.setSize(250, 240);
f1.setLayout(null);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel l1 = new JLabel();
ImageIcon icon = new ImageIcon("res/4.gif");
l1.setBounds(0, 0, 250, 240);
l1.setIcon(icon);
f1.add(l1);
f1.setVisible(true);
}
else if (e.getSource()== j2) {
f.dispose();
i = rand.nextInt(1000);
j = rand.nextInt(500);
f.setLocation(i, j);
f.setVisible(true);
k++;
if (k>=5) {
k = 0;
JOptionPane.showMessageDialog(f, "あなたの恐れのないもがきを止めましょう、子供\n停止你那无畏的挣扎吧,孩子");
i = rand.nextInt(1000);
j = rand.nextInt(500);
JFrame f1 = new JFrame("哈哈哈");
f1.setLocation(i, j);
f1.setSize(310, 330);
f1.setLayout(null);
JLabel l1 = new JLabel();
ImageIcon icon = new ImageIcon("res/3.jpg");
l1.setBounds(0, 0, 300, 300);
l1.setIcon(icon);
f1.add(l1);
f1.setVisible(true);
}
}
else if (e.getSource()== j3) {
f.dispose();
i = rand.nextInt(1000);
j = rand.nextInt(500);
f.setLocation(i, j);
f.setVisible(true);
k++;
if (k>=5) {
k = 0;
JOptionPane.showMessageDialog(f, "想跑?门都没有!!!\n你是逃不掉的,哈哈哈哈");
i = rand.nextInt(1000);
j = rand.nextInt(500);
JFrame f1 = new JFrame("哈哈哈");
f1.setLocation(i, j);
f1.setSize(310, 330);
f1.setLayout(null);
JLabel l1 = new JLabel();
ImageIcon icon = new ImageIcon("res/2.jpg");
l1.setBounds(0, 0, 300, 300);
l1.setIcon(icon);
f1.add(l1);
f1.setVisible(true);
}
}
}
}
(3800字,牛逼)