请问java怎么做这个文本域的?
我的想法是做一个文本域然后下面4个ABCD分别是标签跟按钮的组合,然后那个边框线跟题目2个字就不知道怎么做了,请问这个想法符合么?要怎么做?...
我的想法是做一个文本域 然后下面4个ABCD分别是标签跟按钮的组合,然后那个边框线跟题目2个字就不知道怎么做了,请问这个想法符合么?要怎么做?
展开
2个回答
展开全部
我写了一个满足你的图片的要求,你看看,有什么问题百度hi我:
import java.awt.BorderLayout;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.TitledBorder;
public class TestDemo extends JFrame{
private static final long serialVersionUID = -5355432125621015300L;
private Option[] options = new Option[4];
public TestDemo () {
init();
}
private void init(){
setTitle("我的文本域");
setSize(300,200);
setContentPane(createContentPane());
}
private JPanel createContentPane(){
JPanel pane = new JPanel(new BorderLayout());
pane.add(BorderLayout.NORTH,createQuestionPane());
pane.add(BorderLayout.SOUTH,createOptionsPane());
return pane;
}
private JPanel createOptionsPane(){
JPanel pane = new JPanel();
Option a = new Option(0,"A");
Option b = new Option(1,"B");
Option c = new Option(2,"C");
Option d = new Option(3,"D");
options[0]=a;
options[1]=b;
options[2]=c;
options[3]=d;
pane.add(a);
pane.add(b);
pane.add(c);
pane.add(d);
return pane;
}
private JScrollPane createQuestionPane() {
JScrollPane pane = new JScrollPane();
pane.setBorder(new TitledBorder("题目"));
JTextArea questionArea = new JTextArea();
questionArea.setRows(6);
questionArea.setText("问题\nA.\nB.\nC.\nD.");
questionArea.setLineWrap(true);
questionArea.setEditable(false);
pane.getViewport().add(questionArea);
return pane;
}
class Option extends JCheckBox{
private static final long serialVersionUID = 5569918347028393191L;
int val;
public Option(int val, String txt) {
super(txt);
this.val = val;
}
}
public static void main(String[]args){
TestDemo td=new TestDemo();
td.setVisible(true);
}
}
import java.awt.BorderLayout;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.TitledBorder;
public class TestDemo extends JFrame{
private static final long serialVersionUID = -5355432125621015300L;
private Option[] options = new Option[4];
public TestDemo () {
init();
}
private void init(){
setTitle("我的文本域");
setSize(300,200);
setContentPane(createContentPane());
}
private JPanel createContentPane(){
JPanel pane = new JPanel(new BorderLayout());
pane.add(BorderLayout.NORTH,createQuestionPane());
pane.add(BorderLayout.SOUTH,createOptionsPane());
return pane;
}
private JPanel createOptionsPane(){
JPanel pane = new JPanel();
Option a = new Option(0,"A");
Option b = new Option(1,"B");
Option c = new Option(2,"C");
Option d = new Option(3,"D");
options[0]=a;
options[1]=b;
options[2]=c;
options[3]=d;
pane.add(a);
pane.add(b);
pane.add(c);
pane.add(d);
return pane;
}
private JScrollPane createQuestionPane() {
JScrollPane pane = new JScrollPane();
pane.setBorder(new TitledBorder("题目"));
JTextArea questionArea = new JTextArea();
questionArea.setRows(6);
questionArea.setText("问题\nA.\nB.\nC.\nD.");
questionArea.setLineWrap(true);
questionArea.setEditable(false);
pane.getViewport().add(questionArea);
return pane;
}
class Option extends JCheckBox{
private static final long serialVersionUID = 5569918347028393191L;
int val;
public Option(int val, String txt) {
super(txt);
this.val = val;
}
}
public static void main(String[]args){
TestDemo td=new TestDemo();
td.setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询