java 如何用eclipse 的window builder做一个可视化的发扑克牌程序,里面扑克

2026年09月10日 17:31
有1个网友回答
网友(1):

代码发给你参考

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class PuKe extends JFrame {
public PuKe(String[] ary) {
JPanel jp = new JPanel();
for (int i = 0; i < ary.length; i++) {
//我在桌面上放了两张图片,名字叫大王和小王  
ImageIcon icon = new ImageIcon("C:\\Users\\lenovo\\Desktop\\" + ary[i] + ".jpg");
JLabel jl = new JLabel(icon);
jp.add(jl);
}
this.add(jp);
this.setBounds(300, 200, 500, 500);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}

public static void main(String[] args) {
String[] ary = { "大王", "小王" };
new PuKe(ary);
}
}