我对 C# 和编程的总体经验几乎为零,所以你可能会觉得我的问题很愚蠢。然而,我尝试使用代码创建一个 Windows 窗体,并且我已经成功实现了我想要的。但现在我想向我的所有按钮添加按钮单击事件。我想要 addToDay[i] 清除exerciseBox[i]、setBox[i] 和repBox[i] 中的文本。谢谢。
public NewSchedule2(string path)
{
InitializeComponent();
this.SuspendLayout();
labels = new System.Windows.Forms.Label[7];
exercises = new System.Windows.Forms.TextBox[7];
sets = new System.Windows.Forms.TextBox[7];
reps = new System.Windows.Forms.TextBox[7];
addToDay = new System.Windows.Forms.Button[7];
string[] lines = File.ReadAllLines(path);
for (int i = 0; i < 7; i++)
{
this.labels[i] = new System.Windows.Forms.Label();
this.labels[i].Location = new System.Drawing.Point(40, 40 + i * 50);
this.labels[i].Name = "Label" + i;
this.labels[i].Size = new System.Drawing.Size(110, 20);
this.labels[i].Text = lines[i];
this.Controls.Add(this.labels[i]);
if (lines[i] == "Restday") …Run Code Online (Sandbox Code Playgroud) 所以我想在按下按钮3次后从按钮中删除一个监听器.到目前为止,我有这个
class Q5
{
JFrame frame;
JButton button;
int clickCount = 0;
public static void main (String[] args)
{
Q5 example = new Q5();
example.go();
}
public void go()
{
frame = new JFrame();
button = new JButton ("Should I do it");
button.addActionListener(new ButtonPressListener());
button.addActionListener(new AngelListener());
button.addActionListener(new DevilListener());
button.addActionListener(new ConfusedListener());
frame.getContentPane().add(BorderLayout.CENTER, button);
frame.setVisible(true);
frame.setSize(400,150);
// set frame properties here
}
class ButtonPressListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
clickCount++;
}
}
class AngelListener implements ActionListener
{
public void …Run Code Online (Sandbox Code Playgroud) 我正在用C编写我的rapsberry pi上的gpio引脚.不会让我陷入困境.当我使用==或!=无关紧要时,循环就会卡住.这是因为当程序进入循环时它不会更新while循环使用的变量状态吗?
for(i=0;i<200;i++)
{
uint8_t valu = bcm2835_gpio_lev(SIG);
while(valu == 0)
{
uint8_t valu = bcm2835_gpio_lev(SIG);
data[i] = 0;
dan = dan + 1;
delay(0.001);
}
timeout = 0;
while(val == 1 && timeout < 70)
{
uint8_t val = bcm2835_gpio_lev(SIG);
data[i] = data[i] + 1;
dat = dat + 1;
timeout = timeout + 1;
delay(0.001);
}
delay(0.001);
}
Run Code Online (Sandbox Code Playgroud)
bcm2835指令来自覆盖范围pi使用的broadcom IC的c库.
我知道这是一个愚蠢的问题,但我不知道为什么会这样.这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = (Button)findViewById(R.id.button2);
button.setText("Blabla");
setContentView(R.layout.activity_aiueo);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
Run Code Online (Sandbox Code Playgroud)
片段XML:
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Next"
android:layout_weight="1"
android:onClick="next" />
Run Code Online (Sandbox Code Playgroud)
我只想在启动活动时更改文本,但它会使我的应用程序崩溃.
logcat的
06-23 15:42:05.396: E/AndroidRuntime(13039): FATAL EXCEPTION: main
06-23 15:42:05.396: E/AndroidRuntime(13039): Process: com.shinway.hiragana, PID: 13039
06-23 15:42:05.396: E/AndroidRuntime(13039): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shinway.hiragana/com.shinway.hiragana.table.Aiueo}: java.lang.NullPointerException
06-23 15:42:05.396: E/AndroidRuntime(13039): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215)
06-23 15:42:05.396: E/AndroidRuntime(13039): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2265)
06-23 15:42:05.396: E/AndroidRuntime(13039): at android.app.ActivityThread.access$800(ActivityThread.java:145)
06-23 15:42:05.396: E/AndroidRuntime(13039): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
06-23 …Run Code Online (Sandbox Code Playgroud) 我正在尝试将值K从活动A传递到B.当button单击活动B中的保存时,它将再次将值k传递给活动A. 但如果我想返回A,应用程序崩溃了.
活动A中的一些代码片段
public void onClick(DialogInterface dialog, int item) {
if (item == 0) {
Intent intent = new Intent(getActivity().getApplicationContext(), Project1.class);
intent.putExtra("k",k);
startActivityForResult(intent, 0);
} else if (item == 1) {
Intent intent = new Intent(getActivity().getApplicationContext(), Petrol.class);
intent.putExtra("k", k);
startActivityForResult(intent, 1);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
int button = data.getIntExtra("k1", 0);
if (button == 1) {
switch (requestCode) {
case 0:
String result = data.getStringExtra("text");
String b = data.getStringExtra("a");
as=Long.parseLong(result);
c.setText(" " + …Run Code Online (Sandbox Code Playgroud) 我有一个按钮,但我无法将其中的可绘制对象与中心对齐。这是我的代码 -
<Button
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="@+id/button"
android:background="#ff2fa73a"
android:layout_below="@+id/textView"
android:drawableStart="@mipmap/yes_go"
android:layout_marginTop="156dp" />
Run Code Online (Sandbox Code Playgroud)
<button onclick="hello()">Hello</button>
<script>
function hello() {
alert('Hello');
}
</script>Run Code Online (Sandbox Code Playgroud)
这是我的代码。但这不起作用。当我单击按钮时,什么也没有发生。
我有 2 个按钮“A”和“B”。单击按钮“A”时,我想更改C# 中按钮“B”脚本的颜色有帮助吗?
我是第一次使用 Dreamweaver 进行编码。我的 HTML 水平为中级。
我一直在尝试使用 png 文件作为按钮。我发现一些消息来源表明...
<button src=Home_button> </button>
Run Code Online (Sandbox Code Playgroud)
...会起作用,但我已经尝试过,但无济于事,它不起作用。有什么建议么?
我还使用 CSS 来构建这个非常基本的网站。