Java PokeFrame22
MY:
package pukepai;
import javax.swing.*;
import java.awt.*;
public class test
{
public static void main(String[] args)
{
dapai da = new dapai();
//抽取程序
JFrame jf = new JFrame("LHL's Java");
jf.setLayout(new GridLayout(2, 2));
//外窗口
JInternalFrame jif[] = new JInternalFrame[4];
for(int i=0;i<=3;i++)
{
jif[i]=new createChuangkou(i+1);
jif[i].setVisible(true);
jf.add(jif[i]);
}
jf.setExtendedState(JFrame.MAXIMIZED_BOTH);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class createChuangkou extends JInternalFrame
{
JLayeredPane jp;
int n = 0;
dapai da = new dapai();
Toolkit tk = Toolkit.getDefaultToolkit();
//工具包
int w = (tk.getScreenSize().width)/2;
int h = (tk.getScreenSize().height)/2;
public createChuangkou(int n)
{
super("玩家" + n);
this.n = n;
this.setLayout(null);
jp = this.getLayeredPane();
Setbg();
Setbutton(n);
}
void Setbg()
{
ImageIcon bj = new ImageIcon("img/bj.jpg");
JLabel jl = new JLabel(bj);
jl.setSize(w, h);
jp.add(jl, new Integer(-100));
}
void Setbutton(int k)
{
String[] WpukePhoto = new String[13];
WpukePhoto = da.zuhe();
JButton[] ButtonPhoto = new JButton[13];
ImageIcon PukePhoto = new ImageIcon("img/fang1.jpg");
int pw = PukePhoto.getIconWidth();
int ph = PukePhoto.getIconHeight();
int x1 = 70; // 表示2个扑克牌按钮叠加在一起的宽度
int y1 = 150; // 表示扑克牌按钮底边距离neibuchuangti底边的位置
int kuan = pw - x1;
int firstPositionx = (w - kuan * 13) / 2-35;
int firstPositiony = (h - ph - y1);
for (int i = 0; i <= 12; i++)
{
PukePhoto = new ImageIcon("img/" + WpukePhoto[i]);
ButtonPhoto[i] = new JButton(PukePhoto);
ButtonPhoto[i].setBounds(firstPositionx + kuan * i, firstPositiony, pw, ph);
jp.add(ButtonPhoto[i], new Integer(i));
}
}
}
package pukepai;
import javax.swing.*;
import java.awt.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class PokeFrame22
{
String[] pk = new String[52]; // 存放52张扑克牌文件名
Poke poke = new Poke();
JInternalFrame jif[] = new JInternalFrame[4];
JFrame jf;
Toolkit tk;
int w, h; // 窗体的宽和高
int jw, jh; // neibuchuangti的宽和高
JButton[] jb = new JButton[13];
int x1 = 40; // 表示2个扑克牌按钮叠加在一起的宽度
int y1 = 150; // 表示扑克牌按钮底边距离neibuchuangti底边的位置
public PokeFrame22()
{
jf = new JFrame("包含4个neibuchuangti且每个neibuchuangti包含13张牌按钮的窗体");
jf.setExtendedState(JFrame.MAXIMIZED_BOTH);
tk = Toolkit.getDefaultToolkit();
w = tk.getScreenSize().width;
h = tk.getScreenSize().height;
dedaopai();
tianjianeibuchuangti();
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex)
{
Logger.getLogger(PokeFrame21.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex)
{
Logger.getLogger(PokeFrame21.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex)
{
Logger.getLogger(PokeFrame21.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex)
{
Logger.getLogger(PokeFrame21.class.getName()).log(Level.SEVERE, null, ex);
}
PokeFrame22 pf = new PokeFrame22();
}
public void dedaopai()
{
pk = poke.zuhepai();
}
public void tianjianeibuchuangti()
{
jw = w / 2; // neibuchuangti的宽等于屏幕的宽/2
jh = h / 2; // neibuchuangti的高等于屏幕的高/2
jf.setLayout(new GridLayout(2, 2));
for (int i = 0; i <= 3; i++)
{
jif[i] = new neibuchuangti(i + 1);
jif[i].setVisible(true);
jf.add(jif[i]);
}
}
class neibuchuangti extends JInternalFrame
{
JLayeredPane jp;
int n;
public neibuchuangti(int n)
{
super("玩家" + n);
this.n = n;
this.setLayout(null);
jp = this.getLayeredPane();
tianjiabeijing();
tianjiapaianniu(n);
}
public void tianjiabeijing()
{
ImageIcon bj = new ImageIcon("img/bj.jpg");
JLabel jl = new JLabel(bj);
jl.setSize(jw, jh);
jp.add(jl, new Integer(-100));
}
public void tianjiapaianniu(int k)
{
// 参数x1表示扑克牌重叠的宽度,y1表示扑克牌y方向的起始位置
String pName;
ImageIcon img;
jp = this.getLayeredPane();
pName = "img/" + pk[0];
img = new ImageIcon(pName);
int tw = img.getIconWidth();
int th = img.getIconHeight();
int a = tw - x1-30; // 表示每张牌按钮实际占有的宽度(后一张牌和前一张牌叠加40px)
int xs = (jw - a * 13) / 2; // 表示第一张牌按钮在neibuchuangti中x方向的起始位置
int ys = jh - th - y1; // 表示牌按钮在neibuchuangti中y方向的起始位置
int b = 13 * (k - 1); // 根据不同的k值从pk数组的不同位置取数
for (int i = 0; i <= 12; i++)
{
pName = "img/" + pk[i + b];
img = new ImageIcon(pName);
jb[i] = new JButton(img);
jb[i].setBounds(xs + a * i, ys, tw, th);
jp.add(jb[i], new Integer(i));
}
}
}
}