我有一个扩展 JButton 的类,因为我使用的自定义外观会忽略 isOpaque() 调用。我的意思是,即使我在它和所有父面板上调用了 setOpaque (false),也会呈现按钮的背景。我已经确认这是公司设计人员的 LAF 的一个问题,所以我只能扩展课程。所以我的问题是,如何实现paint() 方法来不呈现背景而只呈现按钮图标?干杯
已解决:如果有人感兴趣,我想要的答案是使用 button.setContentAreaFilled(false);
我在 JTable 中使用 JButton 作为渲染和编辑器,存在以下问题:
任何帮助将不胜感激!
我需要创建一个JButton从 oracle 数据库下载 BLOB 文件。这是我的JButton代码:
JButton btnsave = new JButton("Save");
btnsave.setBounds(478, 542, 120, 23);
getContentPane().add(btnsave);
btnsave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
Run Code Online (Sandbox Code Playgroud)
这个类已经连接到数据库,但这是我的代码的一部分:
Connection con;
String link="*******************************************";
String u="user";
String p="pw";
Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection(link,u,p);
Statement su=con.createStatement();
Run Code Online (Sandbox Code Playgroud)
那么我怎样才能下载一个带有 的 blob 文件ActionListener呢JButton?我还需要创建另一个语句吗?
提前致谢!
在点击任何一个难度按钮后,我试图处理难度窗口,但不会发生.我试过了.dispose,frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);但我无法得到它.它只是放置还是更多?
import java.awt.FlowLayout;
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.GridLayout;
public class Game extends JFrame{
public static JFrame frame = new JFrame();
private JLabel lab;
public static void main(String[] args) {
Game difficulty = new Game();
difficulty.setSize(350,105);
difficulty.setTitle("Difficulty.");
difficulty.setVisible(true);
difficulty.setLocationRelativeTo(null);
/**Game sudoku = new Game();
sudoku.setSize(900, 900);
sudoku.setVisible(false);*/
}
public Game(){
setLayout(new FlowLayout());
lab = new JLabel("Please select your difficulty.");
add(lab);
JButton easy; …Run Code Online (Sandbox Code Playgroud) button1.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent ae) {
exite.setEnabled(true);
}
});
button2.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent ae) {
exite.setEnabled(true);
}
});
button3.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent ae) {
exite.setEnabled(true);
}
});
Run Code Online (Sandbox Code Playgroud)
我这里有3个按钮,但他们做同样的事情.它需要一些代码空间.如何将它们全部分组并分配给一个ActionListener?
像这样的东西.我不知道应该怎么做.
button1.button2.button3.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent ae) {
exite.setEnabled(true);
}
});
Run Code Online (Sandbox Code Playgroud) 
我如何更改 JButton 上的焦点区域,以便当我将光标悬停在按钮上时,我的服装翻转图标在我的光标悬停在实际按钮上之前不会稍微激活。
我用不同的JButtons制作了一个JFrame,我想从另一个类中获取一个图像.有任何想法吗?或者如何在同一个类上绘制但是在执行的操作上?因为它不允许我做任何图纸......我的编译器总是给我错误信息
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.*;
public class red extends JFrame {
public JButton b;
public JButton b1;
public JButton b2;
public JButton b3;
public JButton b4;
public static Image p;
public static Graphics g;
public red() throws IOException {
gui1 x = new gui1();
setTitle(" ");
setSize(1200,700);
setLayout(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
b= new JButton("click");
b1= new JButton();
b.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e0){
b1.setBounds(0, 0, 200, 200);
b.show(false);
add(x);
}
});
b.setBounds(0, 0, 100, 100); …Run Code Online (Sandbox Code Playgroud) 我的游戏重启按钮不起作用,点击它时它会倍增。我不太了解 Java 我认为自己很好。
package snake_game;
public class snake {
public static void main(String arg[]) {
new GameFrame();
// is exacly the same as frame f = new frame();
// this is shorter and does the same job
}
}
Run Code Online (Sandbox Code Playgroud)
GamePanelpackage snake_game;
// import java.awt.event.ActionEvent;
// import java.awt.event.ActionListener;
// import java.awt.Graphics;
// import java.awt.event.KeyAdapter;
// import java.awt.event.KeyEvent;
// or I could write simply
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
import javax.swing.JPanel;
public class GamePanel extends JPanel implements …Run Code Online (Sandbox Code Playgroud) 我在GridLayout中安排了一组按钮.我想根据文本访问特定按钮.有没有办法根据文本检索按钮?