java se,求教 本帖最后由 yxs1112003 于 2011-10-13 18:23:14 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这样可以了。。package com.yhy.test;import java.awt.GridLayout;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JTextField;public class mult{ public static void main(String[] args) { ShowGridLayout frame = new ShowGridLayout(); frame.setTitle("GirdLayout"); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setSize(200, 200); }}class ShowGridLayout extends JFrame { public ShowGridLayout() { setLayout(new GridLayout(2, 2, 5, 5)); add(new JTextField(5)); add(new JTextField(5)); add(new JButton("*")); add(new JButton("=")); }} package com.yhy.test;import java.awt.GridLayout;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JTextField;public class mult { public static void main(String[] args) { mult m = new mult(); ShowGridLayout frame = m.new ShowGridLayout();//实例化一个嵌套类的方法 frame.setTitle("GirdLayout"); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setSize(200, 200); } public class ShowGridLayout extends JFrame { public ShowGridLayout() { setLayout(new GridLayout(2, 2, 5, 5)); add(new JTextField(5)); add(new JTextField(5)); add(new JButton("*")); add(new JButton("=")); } }} 说下LZ的代码,有点受力不讨好。在Mult类内定义内部类 ShowGridLayout 。但还是按照LZ的代码改成可运行的。import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JTextField;public class Mult {static public class ShowGridLayout extends JFrame{public ShowGridLayout(){setLayout(new GridLayout(2,2,5,5));add(new JTextField(5));add(new JTextField(5));add(new JButton("*"));add(new JButton("="));}} public static void main(String[]args){ShowGridLayout frame = new ShowGridLayout();frame.setTitle("GirdLayout");frame.setLocationRelativeTo(null);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);frame.setSize(200,200);}}我觉得LZ的代码最好是改成下面这种形式:代码如下:import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JTextField;import java.awt.GridLayout;public class Mult { public static void main(String[] args) { ShowGridLayout sd = new ShowGridLayout(); sd.init(); }}class ShowGridLayout extends JFrame { //定义一个初始化方法 public void init() { this.setLayout(new GridLayout(2,2,5,5)); this.add(new JTextField(5)); this.add(new JTextField(5)); this.add(new JButton("*")); this.add(new JButton("=")); this.setSize(200,200); this.setTitle("GirdLayout"); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); }}代码不明白为什么的话,可以再问我,很乐意为你解答,希望这些能帮到LZ 请问这个程序中的super.fun()中的super是什么? 为什么我在MANIFEST指定了Class-Path但还是报找不到类啊? SWING实现类似EXCLE功能的表格 如何进行文本筛选 请问哪里有LumaQQ的代码下载?都是没有代码的 关于JFrame的paint问题 如何不用J2SE进行数字签名 java数组的问题,谢谢 那里有Jbuilder书籍下载?? 蔡鸟求助:我的java程序运行了看不到结果 内部匿名类使用外部成员变量,外部成员变量要定义为final? 【初学】Hibernate配置基础问题。
import javax.swing.JFrame;
import javax.swing.JTextField;public class mult{ public static void main(String[] args) {
ShowGridLayout frame = new ShowGridLayout(); frame.setTitle("GirdLayout");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(200, 200); }}
class ShowGridLayout extends JFrame {
public ShowGridLayout() {
setLayout(new GridLayout(2, 2, 5, 5)); add(new JTextField(5));
add(new JTextField(5));
add(new JButton("*"));
add(new JButton("=")); }
}
package com.yhy.test;import java.awt.GridLayout;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;public class mult { public static void main(String[] args) {
mult m = new mult();
ShowGridLayout frame = m.new ShowGridLayout();//实例化一个嵌套类的方法
frame.setTitle("GirdLayout");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(200, 200);
}
public class ShowGridLayout extends JFrame {
public ShowGridLayout() {
setLayout(new GridLayout(2, 2, 5, 5));
add(new JTextField(5));
add(new JTextField(5));
add(new JButton("*"));
add(new JButton("="));
}
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Mult {static public class ShowGridLayout extends JFrame
{
public ShowGridLayout()
{
setLayout(new GridLayout(2,2,5,5));add(new JTextField(5));
add(new JTextField(5));
add(new JButton("*"));
add(new JButton("="));}
}
public static void main(String[]args)
{
ShowGridLayout frame = new ShowGridLayout();frame.setTitle("GirdLayout");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(200,200);}}我觉得LZ的代码最好是改成下面这种形式:代码如下:
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.GridLayout;public class Mult {
public static void main(String[] args) {
ShowGridLayout sd = new ShowGridLayout();
sd.init();
}
}class ShowGridLayout extends JFrame {
//定义一个初始化方法
public void init() {
this.setLayout(new GridLayout(2,2,5,5));
this.add(new JTextField(5));
this.add(new JTextField(5));
this.add(new JButton("*"));
this.add(new JButton("="));
this.setSize(200,200);
this.setTitle("GirdLayout");
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}代码不明白为什么的话,可以再问我,很乐意为你解答,希望这些能帮到LZ