עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

JAVA: Implementation of Button Group

Featured Replies

פורסם

היי לכולם,

אני כותב כרגע תוכנה שלדעתי צריכה Button Group שבעצם תאפשר לי לבחור בין שתי פעולות

ובכך לשלוח את הבחירה לפונקציה אחרת ובכך לקבוע איך היא תפעל הלאה בהתנייה.

אני עובד עם NetBeans IDE 7.0.1 העדכני ביותר ויצרתי JFrame חדש.

כל שדה אחר שהגדרתי, טקסט או כפתורים עובד בלי בעיה. אבל אני לא מצליח להכניס את ה Button Group.

כשאני גורר את ה Button Group ל Panel שיצרתי, הוא לא מופיע.

כאשר אני יוצר אותו ב constructor בקוד ומנסה לחבר בינהם, גם לא מצליח לי.

אם יש למישהו רעיון איך לעזור לי, אשמח.

אם אני לא ברור, אשמח להבהיר.

תודה מראש על העזרה,

לב.

פורסם

אתה צריך ליצור אובייקט מטיפוס ButtonGroup ולהשתמש בשיטה ()add כדי להוסיף את הכפתורים לקבוצה.


public class MyClass extends JFrame
{
public MyClass()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();

JRadioButton buttonA = new JRadioButton("Button A");
JRadioButton buttonB = new JRadioButton("Button B");

ButtonGroup group = new ButtonGroup();
group.add(buttonA);
group.add(buttonB);

panel.add(buttonA);
panel.add(buttonB);

getContentPane().add(panel);
pack();
setLocationRelativeTo(null);
setVisible(true);
}
}

פורסם
  • מחבר

זהו, שבעורך הויזואלי של NetBeans זה עובד קצת אחרת.

אבל הסתדרתי, תודה :)

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.