标签: jbutton

按钮逻辑被忽略 - 为什么?

我正在编写一个加密程序,它会接受常规单词并将它们转换为某个"代码".一切都已完成,但程序忽略了提交按钮代码.我该怎么做才能解决这个问题?

    import javax.swing.*;
    import java.io.*;
    import java.awt.event.*;
    import java.awt.*;
    public class decode extends JFrame {
    private JTextArea textaci;
    private JTextArea textaclr;
    private JLabel lclear;
    private JLabel lcipher;
    private JButton bsubmit;
    private String cleartext;
    private String ciphertext;
    private boolean clrtoci; 


    public decode(){
        super();
        setTitle("Decoder");
        setSize(300,200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new GridBagLayout());
        GridBagConstraints c =new GridBagConstraints();
        c.fill=GridBagConstraints.VERTICAL;
        c.weightx=0.5;
        textaci=new JTextArea();
        textaclr=new JTextArea();
        lclear=new JLabel("cleartext:");
        lcipher=new JLabel("ciphertext:");
        bsubmit=new JButton("Submit");
        bsubmit.setActionCommand("enable");
        textaci.setEditable(true);
        textaci.setLineWrap(true);
        textaclr.setEditable(true);
        textaclr.setLineWrap(true);
        textaci.setText(ciphertext);
        c.gridx=0;
        c.gridy=0;
        add(lclear);
        c.gridx=1;
        c.gridy=0;
        add(textaclr);

        c.gridx=0;
        c.gridy=2;
        add(lcipher);
        c.gridx=3;
        c.gridy=4; …
Run Code Online (Sandbox Code Playgroud)

java swing jbutton

0
推荐指数
1
解决办法
193
查看次数

单击按钮时打开面板

有没有人知道如何使用GUI按钮在java中打开一个新的JPanel?它不在谷歌上.它显示一个关于面板.谢谢您的帮助!

java user-interface swing jpanel jbutton

0
推荐指数
1
解决办法
7840
查看次数

在简单的Java程序中从JButton打开URL?

你好社区:),所以我是一个真正的java newb,对吧?我似乎无法从我的LINK GUI获取打开的URL.目前,它只显示字段值.

这是我的handler.java代码:

google = new JButton("Google");
google.setToolTipText("Open Google");
add(google);
Run Code Online (Sandbox Code Playgroud)

我希望它打开一个URL而不是显示字段值.这是我的actionlistener代码:

    private class HandlerClass implements ActionListener {

    public void actionPerformed(ActionEvent event) {

        JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand()));

    }

}
Run Code Online (Sandbox Code Playgroud)

如果可以的话,我可以得到一些帮助吗?:) 谢谢

java swing awt hyperlink jbutton

0
推荐指数
1
解决办法
9305
查看次数

如何在按下特定按钮之前暂停Java程序?

我目前正在编写类似于brick breaker的游戏,需要知道如何使我的程序等待调用特定函数.

我需要暂停程序,直到按钮之间做出决定.例如,游戏启动,并且用户可以选择他想要在他的游戏中使用哪种颜色.因此,游戏暂停直到他的选择已经完成并且他很高兴然后该程序需要恢复到不同的阶段.

java events swing jbutton wait

0
推荐指数
1
解决办法
2678
查看次数

ActionListener不起作用

当我点击按钮bAddStudent时,没有任何事情发生.也许那是因为我有这些标签?我不知道,这似乎相当不错.有什么想法吗?我会非常感谢任何建议或解决.这是我的代码:

        import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.text.ParseException;
    import java.util.Vector;

    import javax.swing.JButton;
    import javax.swing.JFormattedTextField;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTable;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.text.MaskFormatter;






    public class MainWindow extends JFrame implements ActionListener {

    private JPanel students;
    private JPanel teachers;
    private JPanel lessons;
    private JPanel courses;
    private JPanel addPanel;

    private JTabbedPane tp;
    private JTabbedPane tp2;

    private Container pane;

    private JButton bAddStudent;
    private JButton addTeacher;


    private …
Run Code Online (Sandbox Code Playgroud)

java swing tabs jbutton actionlistener

0
推荐指数
1
解决办法
217
查看次数

如何从使用循环创建的按钮获取输入?

我正在尝试使用Swing在Java中创建一个简单的计算器,并且我按以下方式创建了我的按钮:

//Our number keypad
public static JPanel numbers(){

    //our panel to return
    JPanel panel = new JPanel();

    //Create and add 3x4 grid layout to panel
    GridLayout gl = new GridLayout(3, 4);
    panel.setLayout(gl);

    //For creating and adding buttons to panel
    for(int i = 0; i < 10; i++){

        //Create a new button where the name is the value of i
        String name = "" + i + "";
        JButton button = new JButton(name);

        //add action listener
        button.addActionListener(handler);

        //Add button to panel …
Run Code Online (Sandbox Code Playgroud)

java swing jbutton actionlistener

0
推荐指数
1
解决办法
146
查看次数

Java - 按钮中的按钮

我正在制作一个带有2的程序JButton,但是我有一个MyFrame类,按钮位于另一个名为KnoppenPanel的类中.问题是,当我这样做时,我会得到JButton一个JButton.所以我有2个按钮和另外一个按钮围绕这些.我该如何解决这个问题?

MyFrame:

public class MyFrame extends JFrame {

    Uithangbord u = new Uithangbord();
    KnoppenPanel kp = new KnoppenPanel();

    public MyFrame() {
        setLayout(new FlowLayout());

        add(u);
        add(kp);

        setSize(280, 180);
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
}

public class KnoppenPanel extends JButton implements ActionListener {
private JButton b, b2;
private JPanel p1;

Uithangbord bord = new Uithangbord();

public KnoppenPanel() {
    p1 = new JPanel();
    add(p1);

    b = new JButton("Open");
    p1.add(b);
    b.addActionListener(this);

    b2 = new JButton("Gesloten");
    p1.add(b2);
    b2.addActionListener(this);
}

public void …
Run Code Online (Sandbox Code Playgroud)

java jbutton

0
推荐指数
1
解决办法
57
查看次数

将Jbutton添加到Jtable的每一行

我需要你的帮助,我想在Jtable的每一行添加一个Jbutton(删除按钮).直到现在,我在每一行都添加了按钮,但我对操作有疑问.我尝试过这个,但它不起作用.当我点击按钮时没有任何反应.任何人都可以帮助我,我真的是堆栈.这是我的代码:

`public class Fenetre extends JFrame {

    Statement stmt;
    Map<Integer,Integer> row_table  = new HashMap<Integer,Integer>();
    JButton addUser;


  public Fenetre(){

    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setTitle("JTable");
    this.setSize(600, 140);

    String requeteListeUser=" SELECT * FROM COMPTE_UTILISATEUR";
    try{
    stmt= (Statement) new Connexion().getConnection().createStatement();
    ResultSet resultat= stmt.executeQuery(requeteListeUser);
     resultat.last();
    String  title[] = {"Nom","Prenom","Matricule","Action"};
     int rowCount = resultat.getRow();

     Object[][] data  = new Object[rowCount][4];

     final JTable tableau = new JTable(data,title);
     JButton jButton2= new JButton("Supprimer");



    // this.tableau = new JTable(model);
    tableau.getColumn("Action").setCellRenderer(new ButtonRenderer());

    this.getContentPane().add(new JScrollPane(tableau), BorderLayout.CENTER); 
    int i=0;
        resultat.beforeFirst(); // on repositionne le curseur avant …
Run Code Online (Sandbox Code Playgroud)

java swing jtable jbutton

0
推荐指数
1
解决办法
3275
查看次数

批量添加JButton等

我想知道是否有更好的方法将JButton添加到JPanel或Container等,而不是

p1.add(b1);
p1.add(b2);
p1.add(b3);
Run Code Online (Sandbox Code Playgroud)

你能做到这一点,还是那样的?

p1.add(b1,b2,b3);
Run Code Online (Sandbox Code Playgroud)

java swing jbutton

0
推荐指数
1
解决办法
42
查看次数

使用JButton作为图像

所以,我面临的问题是我想采用JButton的图像模型,而是将其用作图像.我之前没有使用过实施图标,所以我决定做一些搜索.但是,我找不到任何可以理解这里发生的事情.

我试过以下代码:

JButton button = new JButton("Text");
JLabel buttonIcon = new JLabel(button.getIcon());
Run Code Online (Sandbox Code Playgroud)

但是,当我去展示JLabel时,什么都没有出现.这种互动是错的吗?

我也很满意将JButton的模型保存为图像格式,并将其导入.

任何帮助将不胜感激!

java swing jlabel jbutton

0
推荐指数
1
解决办法
77
查看次数

标签 统计

java ×10

jbutton ×10

swing ×9

actionlistener ×2

awt ×1

events ×1

hyperlink ×1

jlabel ×1

jpanel ×1

jtable ×1

tabs ×1

user-interface ×1

wait ×1