0
我很清楚我不假設使用空佈局。但是,目前我正在使用它來測試一些東西。我的程序很簡單:按下墨西哥按鈕以顯示Diplo按鈕。問題是當我的鼠標在出現後滾動到Diplo上時,mex按鈕文本出現在它上面。我目前假設我的問題以某種方式涉及空佈局,不使用paintcomponent或者與方法有關的東西,儘管我不確定它可能會出錯。當將鼠標懸停在JButton上時出現不需要的文本
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class PanelTest extends JPanel
{
//Country Lists
public Country Mex = new Country("Mexico","Empire",15);
public Country Sel;
//Country buttons
public JButton buttonMex;
//Foreign Choices
private JButton buttonAggro;
public JButton buttonDip;
private JButton buttonEspo;
public PanelTest(){
setLayout(null);
//Definitions for button
buttonDip = new JButton();
buttonDip.setForeground(Color.BLACK);
buttonDip.setFont(new Font("Serif", Font.BOLD, 20));
buttonDip.setText("Diplo");
buttonDip.addActionListener(new DipListener());
buttonDip.setSize(100, 50);
buttonDip.setLocation(0,100);
buttonDip.setBorder(null);
buttonDip.setOpaque(false);
buttonDip.setContentAreaFilled(false);
buttonDip.setBorderPainted(false);
buttonDip.setFocusPainted(false);
add(buttonDip);
buttonDip.setEnabled(false);
buttonDip.setVisible(false);
buttonMex = new JButton();
buttonMex.setForeground(Color.BLACK);
buttonMex.setFont(new Font("Serif", Font.BOLD, 20));
buttonMex.setText("Mexico");
buttonMex.addActionListener(new MexListener());
buttonMex.setSize(100, 50);
buttonMex.setLocation(0,0);
buttonMex.setBorder(null);
buttonMex.setOpaque(false);
buttonMex.setContentAreaFilled(false);
buttonMex.setBorderPainted(false);
buttonMex.setFocusPainted(false);
add(buttonMex);
buttonMex.setEnabled(false);
buttonMex.setVisible(false);
//MAIN
buttonValid();
}
public void paintComponent(Graphics g)
{
}
public void buttonValid(){
if(Mex.getVal() == true){
buttonMex.setEnabled(true);
buttonMex.setVisible(true);
}
}
public void FTest()
{
buttonMex.setEnabled(false);
buttonMex.setVisible(false);
buttonDip.setEnabled(true);
buttonDip.setVisible(true);
}
private class MexListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
FTest();
Sel = Mex;
}
}
private class DipListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Mex.setRel(-30);
}
}
這裏是什麼我的程序產生