【发布时间】:2013-12-23 22:58:32
【问题描述】:
我有这段代码:
public void polarprocesso() {
JButton nxtb = new JButton();
JButton bckb = new JButton();
JFrame pola = new JFrame(" Processo de Polarização");
pola.setResizable(false);
JPanel bpanel = new JPanel(new BorderLayout(700, 500));
bpanel.setBackground(Color.white);
pola.add(bpanel);
nxtb.setIcon(new ImageIcon(FSIAP20132014.class.getResource("/Misc/next.png")));
nxtb.setBounds(600, 430, 35, 27);
bpanel.add(nxtb);
nxtb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
contadorbt++;
if (contadorbt > 3) {
contadorbt = 3;
}
if (contadorbt == 0) {
imagem.setIcon(new ImageIcon(FSIAP20132014.class.getResource("/Misc/polar2.gif")));
imagem.setBounds(50, 170, 450, 300);
textopola.setText(PolarTexto.texto1);
} else if (contadorbt == 1) {
textopola.setText(PolarTexto.texto2);
} else if (contadorbt == 2) {
textopola.setText(PolarTexto.texto3);
} else if (contadorbt == 3) {
textopola.setText(PolarTexto.texto4);
}
}
});
bckb.setIcon(new ImageIcon(FSIAP20132014.class.getResource("/Misc/back.png")));
bckb.setBounds(550, 430, 35, 27);
bpanel.add(bckb);
textopola.setText(PolarTexto.texto1);
imagem.setIcon(new ImageIcon(FSIAP20132014.class.getResource("/Misc/polar2.gif")));
imagem.setBounds(50, 170, 450, 300);
bckb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
contadorbt--;
if (contadorbt < 0) {
contadorbt = 0;
}
if (contadorbt == 0) {
textopola.setText(PolarTexto.texto1);
imagem.setIcon(new ImageIcon(FSIAP20132014.class.getResource("/Misc/polar2.gif")));
imagem.setBounds(50, 170, 450, 300);
} else if (contadorbt == 1) {
textopola.setText(PolarTexto.texto2);
} else if (contadorbt == 2) {
textopola.setText(PolarTexto.texto3);
} else if (contadorbt == 3) {
textopola.setText(PolarTexto.texto4);
}
}
});
textopola.setEnabled(false);
textopola.setBackground(Color.gray);
textopola.setBounds(320, 10, 380, 170);
textopola.setOpaque(true);
bpanel.add(imagem);
bpanel.add(textopola);
pola.setResizable(false);
pola.setSize(new Dimension(702, 500));
pola.setLocationRelativeTo(null);
pola.setAlwaysOnTop(true);
pola.setVisible(true);
}
它基本上使我能够制作某种幻灯片,当用户按下下一步和返回按钮时,他会显示不同的文本。但是,一旦我进入幻灯片 2,所有按钮都会消失,只有当我将鼠标悬停在它们上时才会出现。图像也是如此,但它们永远不会出现。
我不知道我是否足够清楚
http://puu.sh/5DUaR
http://puu.sh/5DUbi
puu.sh/5DUbJ
puu.sh/5DUbY
提前谢谢大家
【问题讨论】:
-
如果你使用 BorderLayout-Manager,你应该使用
bpanel.add(Component, {position constraint})而不是仅仅添加组件。在此处查看文档:docs.oracle.com/javase/tutorial/uiswing/layout/border.html
标签: java image swing button slideshow