- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我只是想找出为什么会出现这些错误。我不太清楚为什么它说找不到变量或者为什么它不允许我添加或减去一个 int 。
错误如下:
javac Dial2.java
Dial2.java:53: cannot find symbol
symbol : class arrl
location: class DialFrame
b.addActionListener(new arrl());
^
Dial2.java:56: b is already defined in DialFrame(java.lang.String)
Button b = new Button("<");
^
Dial2.java:57: cannot find symbol
symbol : class arrl
location: class DialFrame
b.addActionListener(new arrl());
^
Dial2.java:127: cannot find symbol
symbol : variable pastNumbeCount
location: class DialFrame.ArrowListener
arrowIndex = (arrowIndex + pastNumbeCount - 1) % pastNumberCount;
^
Dial2.java:127: operator + cannot be applied to int,pastNumbeCount
arrowIndex = (arrowIndex + pastNumbeCount - 1) % pastNumberCount;
^
Dial2.java:127: operator - cannot be applied to <nulltype>,int
arrowIndex = (arrowIndex + pastNumbeCount - 1) % pastNumberCount;
^
Dial2.java:128: cannot find symbol
symbol : variable arrowindex
location: class DialFrame.ArrowListener
phoneNumber.setText(pastNumbers[arrowindex - 1]);
^
Dial2.java:133: cannot find symbol
symbol : variable pastNumberindex
location: class DialFrame.ArrowListener
phoneNumber.setText(pastNumberindex);
^
8 errors
这是一个简单的电话拨号器的代码:
cat Dial2.java
import java.awt.*;
import java.awt.event.*;
// Driver class
public class Dial2 {
public static void main(String[] args) {
Frame frame = new DialFrame("Dial");
frame.pack();
frame.setVisible(true);
}
}
// Frame class
class DialFrame extends Frame {
private TextField phoneNumber = new TextField();
private String pastNumbers[] = new String[10];
private int pastNumberCount = 0;
private int pastNumberIndex = 0;
private int arrowIndex = 0;
// Constructor
public DialFrame(String title) {
// Set title
super(title);
// set all pastNumbers to empty string
for (int x = 0; x < pastNumbers.length; x++)
pastNumbers[x] = "";
// Make text field non-editable and put at top of frame
phoneNumber.setEditable(false);
add("North", phoneNumber);
// Create panel to hold buttons and set its layout
Panel buttonPanel = new Panel();
buttonPanel.setLayout(new GridLayout(4, 3, 10, 10));
DigitListener dl = new DigitListener();
ArrowListener arrl = new ArrowListener();
// Create first nine buttons, attach a listener to each,
// and add buttons to buttonPanel
for (int i = 1; i <= 9; i++) {
Button b = new Button(i + "");
b.addActionListener(dl);
buttonPanel.add(b);
}
// **1** Add your two new buttons to your panel, along with an
// an arrow listener for both
Button b = new Button(">");
b.addActionListener(new arrl());
b = new Button("0");
Button b = new Button("<");
b.addActionListener(new arrl());
buttonPanel.add(b);
// Create a panel to hold buttonPanel; put it at the
// center of the frame
Panel centerPanel = new Panel();
centerPanel.add(buttonPanel);
add("Center", centerPanel);
// Create a panel to hold the "Dial" button; put it at
// the bottom of the frame
Panel bottomPanel = new Panel();
b = new Button("Dial");
b.addActionListener(new DialListener());
bottomPanel.add(b);
add("South", bottomPanel);
// Attach window listener
addWindowListener(new WindowCloser());
}
private void addPastNumber(String num) {
boolean numberAlreadyAdded = false;
for (int x=0; x < pastNumbers.length; x++) {
if (pastNumbers[x].equals(num)) {
numberAlreadyAdded = true; break;
}
}
if (!numberAlreadyAdded) {
pastNumbers[pastNumberIndex] = num;
pastNumberIndex++;
if (pastNumberCount < 10) pastNumberCount++;
if (pastNumberIndex == pastNumbers.length) pastNumberIndex = 0;
}
arrowIndex = pastNumberIndex;
}
// Listener for all buttons
class DigitListener implements ActionListener {
public void actionPerformed(ActionEvent evt) {
String buttonLabel = evt.getActionCommand();
// append the digit on the newly pressed key
phoneNumber.setText(phoneNumber.getText() + buttonLabel);
}
}
// Listener for all buttons
class DialListener implements ActionListener {
public void actionPerformed(ActionEvent evt) {
addPastNumber(phoneNumber.getText());
phoneNumber.setText("Dialing...");
// pause for two seconds, or 2000 millisecond
try {
Thread.sleep(2000);
} catch (InterruptedException e) {}
phoneNumber.setText("");
}
}
// Listener for "arrow" buttons
class ArrowListener implements ActionListener {
public void actionPerformed(ActionEvent evt) {
// ** 2 **
String buttonLabel = evt.getActionCommand();
if (buttonLabel == "<")
{
arrowIndex = (arrowIndex + pastNumbeCount - 1) % pastNumberCount;
phoneNumber.setText(pastNumbers[arrowindex - 1]);
}
else
{
arrowIndex = (arrowIndex + 1) % pastNumberCount;
phoneNumber.setText(pastNumberindex);
}
}
}
// Listener for window
class WindowCloser extends WindowAdapter {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
}
}
任何帮助或信息将不胜感激。
说明:如果 PastNumbers 数组中的当前索引为 9,则按下“>”键将显示索引 0 处存储的数字。如果当前索引为 0,则按“<”键将显示索引 9 处存储的数字。
要进行此设置,我需要从按钮中检索标签。如果是“<”键,请将我的箭头索引设置为: (arrowIndex + 过去的数字计数 - 1) % 过去的数字计数;并将过去号码数组中该索引处的过去号码添加到我的电话号码文本字段中。
否则,我需要将数组索引设置为:(arrowIndex + 1) % pastNumberCount,并将该索引处的过去数字添加到文本字段中。
最佳答案
使用new ArrowListener()代替new arl(); (arrl 不是一个类,它是一个对象)使用 PastNumberCount 而不是 PastNumbeCount (r 缺失)使用 arrowIndex 代替 arrowindex (i 应该大写)使用过去编号索引而不是过去编号索引(i应该是大写)
你的程序中有很多错别字。
问候,亚什
关于java - 我的 ButtonListener Dial 程序出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13041208/
无法运行结构第一个网络示例 这是我运行时的日志:./byfn up / ___| |_ _| / \ | _ \ |_ _| \___ \ | | / _ \
AWS kubernetes集群中的所有节点(服务器版本:version.Info {主要:“1”,次要:“0”,GitVersion:“v1.0.6”,GitCommit:“388061f00f0d
我有一个包含三个节点的 kubernetes 集群:10.9.84.149、10.9.105.90 和 10.9.84.149。当我的应用程序尝试在某个 pod 内执行命令时: kuebctl exe
任何人都可以帮助我修复以下错误。我正在尝试通过cli在对等节点上安装chaincode。我正确配置了cli容器。但是不知何故我收到此错误。 grpc: addrConn.createTransport
I am writing a simple Go web application with Redis (trying out redis for the first time) on Wind
我们已经在 Azure 公共(public)云中使用 ACS 引擎部署了 K8S 集群。我们能够创建部署和服务,但是当我们使用“kubectl exec -ti (pod name) (command
我们有客户要求为宽带用户提供拨号的“精简”版本和所有花里胡哨的功能。 该解决方案将使用 Flex/Flash/Java EJB 和一些 jsp。 Web服务器有没有办法区分两者? 最佳答案 你不关心用
我有三个分机号,分机号。 2000 , 2001 , 2002 .另外,我可以从一个分机调用另一个分机。在调用任何扩展时,它会出现这样的错误 Asterisk 中的扩展错误没有应用程序“拨号” 我的
是否可以通过他们的拨号调制解调器在同一国家/地区的计算机 A 与计算机 B 通话?我的意思是将计算机用作电话(使用拨号调制解调器)我不需要转移语音只是:1)电脑A拨电脑B(有电话号码)2)计算机B看到
如何在等待连接成功的同时调用号码并向来电者播放音乐? 下面的代码在执行 (这是逻辑)之前等待音乐结束 http://com.twilio.music.ambient.s3.amazonaw
我正在 GitHub 上开发一个 IDE 的分支,主要问题之一是它将文件保存到 cookie,而不是普通计算机。因此,我需要一种保存和打开文件的方法。我已经使用 blob 关闭了保存文件系统。然而,根
我正在开发一个小型 AMQP 消费者,我想测试我的消费者代码,但我很难模拟 amqp.Dial。我添加了一些接口(interface)以便我可以模拟 Connection 和 Channel 并添加了
我有一个应用程序,可以让用户调用他们想要添加到通话中的号码。每个用户都受其帐户中余额的影响。 拨号是使用 TwiML 执行的 因此,根据我每分钟的金额,我以秒为单位计算剩余余额,并将其设置为 tim
我正在开发一个小型 AMQP 消费者,我想测试我的消费者代码,但我很难模拟 amqp.Dial。我添加了一些接口(interface)以便我可以模拟 Connection 和 Channel 并添加了
我正在使用 Twilio Java API,但我似乎无法构建将调用 Sip 分机的响应。 TwiMLResponse twiml = new TwiMLResponse(); Sip sip = ne
我只是想找出为什么会出现这些错误。我不太清楚为什么它说找不到变量或者为什么它不允许我添加或减去一个 int 。 错误如下: javac Dial2.java Dial2.java:
我正在将一个复杂的软件从 IRIX 移植到 Linux Red-Hat。它现在使用 libSgm 中的 Dial 小部件(例如,请参阅 here)。我搜索了很长一段时间,没有找到任何可以在 Linux
刚刚按照 Ubuntu 14.04 中的存储库的官方说明安装了 Docker CE 安装成功,守护进程正在运行 $ ps aux | grep docker [...] /usr/bin/docker
此代码从我的应用程序成功调用 Intent dialer = new Intent("android.intent.action.CALL_PRIVILEGED"); mail.setData(Uri
我需要能够选择应该从哪个 IP 地址发送我的 HTTP 请求。现在在我的代码中,对于 DNS 缓存,我根据 this 使用以下内容: defaultTransport.DialContext = fu
我是一名优秀的程序员,十分优秀!