jframe dy not dy d actionListener出现
我是初学者,我已经编写了此代码,但是它似乎不起作用。我已经运行了代码,由于某些原因,jframe
没有出现(班级名称在匈牙利语中,不介意)。
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class főMásolgató implements ActionListener {
JButton b;
JLabel label;
JTextField tfield;
JFrame frame;
public void főMásolgató(){
frame = new JFrame();
b = new JButton("Másolás");
label = new JLabel("");
tfield = new JTextField();
frame.add(b);
frame.add(label);
frame.add(tfield);
b.addActionListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
label.setText(tfield.getText());
}
}
public class másolgatóHasználata {
public static void main(String args[]){
new főMásolgató();
}
}
I'm a beginner and I've written this code but it does not seem to work. I've run the code and for some reasons the JFrame
does not appear (the class name is in Hungarian, do not mind it).
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class főMásolgató implements ActionListener {
JButton b;
JLabel label;
JTextField tfield;
JFrame frame;
public void főMásolgató(){
frame = new JFrame();
b = new JButton("Másolás");
label = new JLabel("");
tfield = new JTextField();
frame.add(b);
frame.add(label);
frame.add(tfield);
b.addActionListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
label.setText(tfield.getText());
}
}
public class másolgatóHasználata {
public static void main(String args[]){
new főMásolgató();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
void
方法főmásolgató
不是类构造函数。在您的情况下,如果要创建一个
főmásolgató
的实例,则需要调用由Java定义的默认NO-ARG构造函数,而不是void
methodfőmásolgató
。这是您的代码调整的一个示例:
The
void
methodfőMásolgató
is not a class constructor.In your case, if you want to create an instance of
főMásolgató
, you need to invoke the default no-arg constructor defined by Java, instead of thevoid
methodfőMásolgató
.Here is an example with your code tweaked:
您的错误是
函数不是构造函数。
如果您这样做,您的代码将工作:
因为他将在这里使用默认构造函数。然后他将打电话给您的功能。
或者,您可以通过更改来修复它:
那时
您的块是构造函数。
提示: 您可以按线路运行。这将使您知道您的块是否运行。
Your mistake is that
is a function not a constructor.
Your code will work if you do:
because here he will use the default constructor. then he will call your function.
Or you can fix it by changing:
to
Then your block is the constructor.
Hint: you can debug this by running line by line. This will let you know if your block was run or not.