跪求UI中的JRadioButton中的ButtonGroup怎么弄? 本帖最后由 zhen1606 于 2012-01-19 08:47:38 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Class MainWindowpackage dialog;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JRadioButton;import javax.swing.JTextField;import javax.swing.UIManager;import javax.swing.UnsupportedLookAndFeelException;import net.miginfocom.swing.MigLayout;public class MainWindow extends JFrame { private JMenuBar menuBar = new JMenuBar(); private JMenu fileMenu = new JMenu("File"); private JMenu fileEdit = new JMenu("Edit"); private JMenu fileHelp = new JMenu("Help"); private JMenuItem newMenuItem = new JMenuItem("New Customer"); private JMenuItem openMenuItem = new JMenuItem("Open..."); private JMenuItem saveMenuItem = new JMenuItem("Save"); private JButton showAllButton = new JButton("Display all customers"); private ArrayList<Customer> customers = new ArrayList <Customer> (); //Constructor public MainWindow(){ this.setLayout(new MigLayout()); this.setJMenuBar(menuBar); menuBar.add(fileMenu); menuBar.add(fileEdit); menuBar.add(fileHelp); fileMenu.add(newMenuItem); fileMenu.add(openMenuItem); fileMenu.add(saveMenuItem); this.add(showAllButton); showAllButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (customers.isEmpty()) { JOptionPane.showMessageDialog(MainWindow.this,"No customers!"); } else { System.out.println(customers.toString()); } } }); newMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { CustomerDialog dialog = new CustomerDialog(MainWindow.this,true); dialog.setLocationRelativeTo(MainWindow.this); dialog.setVisible(true); Customer customer = dialog.getCustomer(); if (customer != null) { customers.add(customer); } } }); } //Main method public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ignored){ } MainWindow mainWindow = new MainWindow(); mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE); mainWindow.setSize(400,300); mainWindow.setLocationRelativeTo(null); mainWindow.setVisible(true); }} Class Customerpackage dialog;public class Customer { private String name; private String address; private double balance; public Customer(String name, String address, double balance) { this.name = name; this.address = address; this.balance = balance; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public String toString() { return "Customer [address=" + address + ", balance=" + balance + ", name=" + name + "]"; }} 同步代码块求分析 请教数据库连接池的问题 为什么我的进入cmd中后就打印不出汉字了?????????、、 怎么用java写个读入文件的函数? html如何设置input的无边框效果 一个关于APPLET的问题 一个如何学习Java的问题 jbuilder7.0中,如何调试apleet? java的日期问题(今天下班前结账2002-7-24) 套接字 awt里applet 重绘的问题 没明白构造器和构造器方法是什么东西
package dialog;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import net.miginfocom.swing.MigLayout;public class MainWindow extends JFrame {
private JMenuBar menuBar = new JMenuBar();
private JMenu fileMenu = new JMenu("File");
private JMenu fileEdit = new JMenu("Edit");
private JMenu fileHelp = new JMenu("Help");
private JMenuItem newMenuItem = new JMenuItem("New Customer");
private JMenuItem openMenuItem = new JMenuItem("Open...");
private JMenuItem saveMenuItem = new JMenuItem("Save");
private JButton showAllButton = new JButton("Display all customers");
private ArrayList<Customer> customers = new ArrayList <Customer> (); //Constructor
public MainWindow(){
this.setLayout(new MigLayout());
this.setJMenuBar(menuBar);
menuBar.add(fileMenu);
menuBar.add(fileEdit);
menuBar.add(fileHelp);
fileMenu.add(newMenuItem);
fileMenu.add(openMenuItem);
fileMenu.add(saveMenuItem);
this.add(showAllButton);
showAllButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if (customers.isEmpty())
{
JOptionPane.showMessageDialog(MainWindow.this,"No customers!"); }
else
{
System.out.println(customers.toString());
}
}
}); newMenuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
CustomerDialog dialog = new CustomerDialog(MainWindow.this,true);
dialog.setLocationRelativeTo(MainWindow.this);
dialog.setVisible(true);
Customer customer = dialog.getCustomer();
if (customer != null)
{
customers.add(customer); }
}
});
} //Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception ignored){ }
MainWindow mainWindow = new MainWindow();
mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE);
mainWindow.setSize(400,300);
mainWindow.setLocationRelativeTo(null);
mainWindow.setVisible(true);
}
}
package dialog;public class Customer {
private String name;
private String address;
private double balance; public Customer(String name, String address, double balance)
{
this.name = name;
this.address = address;
this.balance = balance;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getAddress() {
return address;
} public void setAddress(String address) {
this.address = address;
} public double getBalance() {
return balance;
} public void setBalance(double balance) {
this.balance = balance;
} public String toString() {
return "Customer [address=" + address + ", balance=" + balance
+ ", name=" + name + "]";
}
}