English 中文(简体)
A. 确定一个县的规模和行动听众
原标题:Setting the size of a button and action listener

问题1:

我试图确定我ton子的大小,但似乎并没有改变,而是总是要填满我所希望的 t。

Problem 2:

当我用我的电文补充公开无效的行动(行动)时,似乎没有显示。 也许,这只是因为填满整个空间的纽子,但我不知道。

Here is the code for the buttons:

import java.awt.event.*;

import javax.swing.*;
import java.awt.*;
   public class HockeyGame extends JFrame implements 
      ActionListener, KeyListener, Runnable, WindowListener  //, ActionListener
        {
        Thread t;
        int xpuck, ypuck,xspeed,yspeed,gx,gy,redx2,redy2,lg,rg, redscore, bluescore,
            redx,redy, gx2, gy2, bluex, bluey,bluex2,bluey2,rg2,lg2;
        //int SQUARE_SIZE=10;
        public HockeyGame ( ) {

            }

        public static void main ( String [ ] commandLine ) {
            HockeyGame hg=new HockeyGame();
            hg.init();
        }

        public void actionPerformed1(ActionEvent e) {
            JOptionPane.showMessageDialog(null,"testing");
        }
        public void init() {
            Button b;           
            b = new Button("Click me");
            b.addActionListener(this); 
            b.setSize(40, 40);
            add(b);
            t=new Thread(this);
            this.addKeyListener(this);
            this.setFocusable(true);
            setSize(700,700);
            setVisible ( true );

Any help is appreciatedasd

问题回答

Start with simple exercises to make you strong in the basics.

(1) 你的布顿填补了这个空间,因为你的内容铺设的落空是边界。 规定流放的布局。

2) The function name should be exactly the same as that defined in Action Listener.


public void actionPerformed(ActionEvent e)
{}

我所说的话,在你坚实基础之前,不会有任何意义。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签