0
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);

私の画像アイコンが表示されず、同じディレクトリに同じ名前がありますか? 助けてください

4

2 に答える 2

0

たとえば、 case ((hours>=0)&&(hours<2)):amount = 0.50 は、最大 2 時間 50p; で動作します。2 ~ 4 時間 £1; 4 ~ 8 時間 £2; 8 ~ 12 時間 £3; 12 ~ 24 時間 £5; – あなたの範囲で列挙型を作成することができます:

public enum Hours {

U2,2TO4,4TO8,8TO12,12TO24;

}`

Hours value = HOURS.value // 単なる例です。ゲッターで取得する必要があります

swicth(value){ case: U2 :/アクション

case 2TO4 :/アクション

case 4TO8 :/アクション

} ..

于 2011-12-21T15:07:39.180 に答える
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);
}

`

于 2011-12-21T13:51:04.133 に答える