求助 一个简单的连词游戏 一个很简单的连词游戏左右各4个按钮 左边的是英文单词 右边的是中文解释只要把左边的单词与右边匹配的中文释义连起来就好了对GUI这块不了解 有高手能随便帮忙写上一个吗 或者给个类似的东西参考一下也行多谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.awt.BorderLayout;import java.awt.Color;import java.awt.Graphics;import java.awt.HeadlessException;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.Box;import javax.swing.JButton;import javax.swing.JFrame;public class Tian_ci extends JFrame{ private JButton bt_eng; private JButton bt_chi; public Tian_ci() throws HeadlessException { super(); init(); this.add(bt_chi,BorderLayout.WEST); this.add(bt_eng,BorderLayout.EAST); this.add(Box.createHorizontalStrut(100)); this.setSize(300, 150); this.setLocationRelativeTo(null); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void init(){ bt_chi=new JButton("英文"); bt_chi.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(e.getSource().equals(bt_chi)){ Graphics g = getGraphics(); g.setColor(Color.blue); g.drawLine(50, 100, 220, 100); } } }); bt_eng=new JButton("English"); } public static void main(String[] args) { // TODO 自动生成方法存根 new Tian_ci(); }}简单写下,希望对你有所帮助。 太感谢了不过 如果我需要写很多按钮的时候,就不能用BorderLayout实现了是么是不是要用FlowLayout? 我试了一下 好像也不怎么对 能告诉我是怎样做的吗谢谢!! 可以用,把多个按钮用flowLayout放在一个panel里,再把panel放到borderLayout布局里。 能麻烦写个代码说明一下吗 我刚刚接触GUI 是个新手 谢谢~~~ 借用下5楼bobolnear的代码,布局可以如下(具体的按钮事件没写):import java.awt.BorderLayout; import java.awt.Color; import java.awt.Graphics; import java.awt.GridLayout;import java.awt.HeadlessException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel;public class Tian_ci extends JFrame{ private JButton bt_en1; private JButton bt_en2;private JButton bt_en3;private JButton bt_en4;private JButton bt_ch1; private JButton bt_ch2; private JButton bt_ch3; private JButton bt_ch4; private JPanel panel_ch;private JPanel panel_en;public Tian_ci() throws HeadlessException { super(); init(); this.add(panel_ch,BorderLayout.WEST); this.add(panel_en,BorderLayout.EAST); this.add(Box.createHorizontalStrut(100)); this.setSize(300, 150); this.setLocationRelativeTo(null); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void init(){ bt_ch1=new JButton("英文1"); /*bt_ch1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(e.getSource().equals(bt_ch1)){ Graphics g = getGraphics(); g.setColor(Color.blue); g.drawLine(50, 100, 220, 100); } } }); */bt_ch2=new JButton("英文2"); bt_ch3=new JButton("英文3"); bt_ch4=new JButton("英文4");bt_en1=new JButton("English1"); bt_en2=new JButton("English2");bt_en3=new JButton("English3");bt_en4=new JButton("English4");panel_ch = new JPanel(new GridLayout(4,1));panel_ch.add(bt_ch1,"1");panel_ch.add(bt_ch2,"2");panel_ch.add(bt_ch3,"3");panel_ch.add(bt_ch4,"4");panel_en = new JPanel(new GridLayout(4,1));panel_en.add(bt_en1,"1");panel_en.add(bt_en2,"2");panel_en.add(bt_en3,"3");panel_en.add(bt_en4,"4");} public static void main(String[] args) { // TODO 自动生成方法存根 new Tian_ci(); } } 1.选择使用合适的布局 可以用Grid或GridBag 以上有提到2.选择使用JToggleButton 可以保持按下状态 用以区分选择3.逻辑判断与操作启动基本都在按钮响应方法中执行 急,在线 java 中怎样把 ' 换为 \' 怎么把一个网页的Html源码贴在文本框中 有关于sql server 2005的,路过的帮看看这个装的全不全 java5中annotation验证功能是怎么做的 如何隐藏真实的URL? 求一个简单的算法!!! 一般医院软件用什么数据库 新手上路,请指点一二,有关错误分析 本人用 Visual J++ 做的扫雷程序,欢迎下载 文件下载的问题!!! 如何实现四则运算的输入操作 程序有错误,高手帮帮我啦! jni的内存泄漏问题
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Tian_ci extends JFrame{
private JButton bt_eng;
private JButton bt_chi;
public Tian_ci() throws HeadlessException {
super();
init();
this.add(bt_chi,BorderLayout.WEST);
this.add(bt_eng,BorderLayout.EAST);
this.add(Box.createHorizontalStrut(100));
this.setSize(300, 150);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void init(){
bt_chi=new JButton("英文");
bt_chi.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(bt_chi)){
Graphics g = getGraphics();
g.setColor(Color.blue);
g.drawLine(50, 100, 220, 100);
}
}
});
bt_eng=new JButton("English");
}
public static void main(String[] args) {
// TODO 自动生成方法存根
new Tian_ci(); }}
简单写下,希望对你有所帮助。
不过 如果我需要写很多按钮的时候,就不能用BorderLayout实现了是么
是不是要用FlowLayout? 我试了一下 好像也不怎么对 能告诉我是怎样做的吗
谢谢!!
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Tian_ci extends JFrame{ private JButton bt_en1;
private JButton bt_en2;
private JButton bt_en3;
private JButton bt_en4;
private JButton bt_ch1;
private JButton bt_ch2;
private JButton bt_ch3;
private JButton bt_ch4; private JPanel panel_ch;
private JPanel panel_en;public Tian_ci() throws HeadlessException {
super();
init(); this.add(panel_ch,BorderLayout.WEST);
this.add(panel_en,BorderLayout.EAST);
this.add(Box.createHorizontalStrut(100));
this.setSize(300, 150);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} public void init(){
bt_ch1=new JButton("英文1");
/*bt_ch1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(bt_ch1)){
Graphics g = getGraphics();
g.setColor(Color.blue);
g.drawLine(50, 100, 220, 100);
}
}
}); */
bt_ch2=new JButton("英文2");
bt_ch3=new JButton("英文3");
bt_ch4=new JButton("英文4");bt_en1=new JButton("English1");
bt_en2=new JButton("English2");
bt_en3=new JButton("English3");
bt_en4=new JButton("English4");panel_ch = new JPanel(new GridLayout(4,1));panel_ch.add(bt_ch1,"1");
panel_ch.add(bt_ch2,"2");
panel_ch.add(bt_ch3,"3");
panel_ch.add(bt_ch4,"4");panel_en = new JPanel(new GridLayout(4,1));panel_en.add(bt_en1,"1");
panel_en.add(bt_en2,"2");
panel_en.add(bt_en3,"3");
panel_en.add(bt_en4,"4");}
public static void main(String[] args) {
// TODO 自动生成方法存根
new Tian_ci(); } }
2.选择使用JToggleButton 可以保持按下状态 用以区分选择
3.逻辑判断与操作启动基本都在按钮响应方法中执行