package cuison_final_lab2;
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.*;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.border.Border;
public class Cuison_Final_Lab2 extends JPanel{
private Label myLabel;
private Panel myPanel;
private Frame frame;
public Cuison_Final_Lab2(){
super(new BorderLayout());
frameSetting();
}
public static void main(String[] args) {
Cuison_Final_Lab2 my = new Cuison_Final_Lab2();
my.myOutput();
}
private void frameSetting(){
frame = new Frame("Lab2");
frame.setSize(200, 200);
frame.setLayout(new GridLayout(3, 1));
frame.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
myLabel = new Label();
myLabel.setAlignment(Label.CENTER);
myPanel = new Panel();
myPanel.setLayout(new FlowLayout());
frame.add(myLabel);
frame.add(myPanel);
frame.setVisible(true);
}
private JPanel myOutput(){
myLabel.setText("Select options");
Button showItButton = null;
final int numButtons = 1;
ButtonGroup myGroup = new ButtonGroup();
JCheckBox[] checkButtons = new JCheckBox[numButtons];
String chkDistance="";
String chkVolume = "";
checkButtons[0] = new JCheckBox("Distance");
checkButtons[0].setActionCommand(chkDistance);
checkButtons[1] = new JCheckBox("Volume");
checkButtons[1].setActionCommand(chkVolume);
for (int x = 0; x < numButtons; x++) {
myGroup.add(checkButtons[x]);
}
checkButtons[0].setSelected(true);
showItButton = new Button("OK");
showItButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String command = myGroup.getSelection().getActionCommand();
}
});
我不能回复这个。
return createPane(checkButtons,showItButton);
我创建了一个JPanel createPane但我无法返回它。还有另一种方法可以归还吗?
myOutput使用create Pane来创建窗格 包含描述,一列复选框和Show 它!按钮。
}
private JPanel createPane(String description, JCheckBox[] checkButtons,
JButton showButton) {
int numChoices = checkButtons.length;
JPanel box = new JPanel();
JLabel label = new JLabel(description);
box.setLayout(new BoxLayout(box, BoxLayout.PAGE_AXIS));
box.add(label);
for (int i = 0; i < numChoices; i++) {
box.add(checkButtons[i]);
}
JPanel pane = new JPanel(new BorderLayout());
pane.add(box, BorderLayout.PAGE_START);
pane.add(showButton, BorderLayout.PAGE_END);
return pane;
}
public void distance(){
String inputNum;
double convert;
inputNum = JOptionPane.showInputDialog("Enter Distance(meters)");
Checkbox check = new Checkbox();
Checkbox chkKilometers = new Checkbox("Kilometers");
Checkbox chkCentimeters = new Checkbox("Centimeters");
Checkbox chkYards = new Checkbox("Yards");
convert =Double.parseDouble(inputNum)/1000;
JOptionPane.showMessageDialog(null, String.format("meters to kilometers: "+convert));
}
}
答案 0 :(得分:1)
行return createMe(...)
行在void函数内声明。虚空功能不会返回任何内容。这就是为什么它是非法的。