coins = new JPanel();
coins.setLayout(new GridLayout(0,1));
ImageIcon tenP1 = new ImageIcon("10p.jpeg");
tenP = new JButton("", tenP1);
ImageIcon twentyP1 = new ImageIcon("20p.jpeg");
twentyP = new JButton("", twentyP1);
ImageIcon fiftyP1 = new ImageIcon("50p.jpeg");
fiftyP = new JButton("", fiftyP1);
ImageIcon pound = new ImageIcon("pound.jpeg");
onePound = new JButton("", pound);
我的图片图标不显示,我将它们放在同一目录中同名?请帮忙
答案 0 :(得分:0)
试试这个:
public static void main(String[] args) {
JFrame frame = new JFrame("Test image");
JPanel pane = new JPanel();
ImageIcon img = new ImageIcon(TestImage.class.getResource("/img.png"));
ImageIcon img2 = new ImageIcon(TestImage.class.getResource("/img2.png"));
ImageIcon img3 = new ImageIcon(TestImage.class.getResource("/img3.png"));
ImageIcon img4 = new ImageIcon(TestImage.class.getResource("/img4.png"));
ImageIcon img5 = new ImageIcon(TestImage.class.getResource("/img5.png"));`
JButton testBut = new JButton(img);
JButton testBut2 = new JButton(img2);
JButton testBut3 = new JButton(img3);
JButton testBut4 = new JButton(img4);
JButton testBut5 = new JButton(img5);
pane.setLayout(new BorderLayout());
pane.add(testBut,BorderLayout.NORTH);
pane.add(testBut2,BorderLayout.WEST);
pane.add(testBut3,BorderLayout.EAST);
pane.add(testBut4,BorderLayout.SOUTH);
pane.add(testBut5,BorderLayout.CENTER);
frame.add(pane);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
`
答案 1 :(得分:0)
好的,谢谢你知道如何在switch语句中使用operator之间的情况,例如case((hours> = 0)&&&(hours< 2)):amount = 0.50就可以了 最多2小时50便士; 2至4小时£1; 4至8小时£2; 8至12小时3英镑; 12至24小时£5; - 您可以使用范围创建枚举:
public enum Hours {
U2,2TO4,4TO8,8TO12,12TO24;
}`
Hours value = HOURS.value
//只是一个例子,你必须得到一个getter
swicth(value){
case: U2 :
/动作
case 2TO4 :
/动作
case 4TO8 :
/动作
}
..