import javax.swing.*; import static javax.swing.JFrame.*; import java.awt.*; class MyJFrame extend
importjavax.swing.*;importstaticjavax.swing.JFrame.*;importjava.awt.*;classMyJFrameex...
import javax.swing.*;
import static javax.swing.JFrame.*;
import java.awt.*;
class MyJFrame extends JFrame{
JPanel panel1=new JPanel();
JPanel panel2=new JPanel();
JTextField textfield=new JTextField(10);
JButton button[]=new JButton[5];
//PoliceListen listener;
String buttonName[]={"北","南","西","东","中"};
String direct[]={BorderLayout.NORTH,BorderLayout.SOUTH,BorderLayout.WEST,BorderLayout.EAST,BorderLayout.CENTER };
MyJFrame(String s,int x,int y,int w,int h){
setLayout(new GridLayout(2,1));
addComponent();
setTitle(s);
setBounds(x,y,w,h);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
}
void addComponent(){
panel1.add(textfield);
add(panel1);
panel2.setLayout(new BorderLayout());
// listener=new PoliceListen();
// listener.setJTextField(textfield);
//listener.setJButton(button);
for(int i=0;i<5;i++){
button[i]=new JButton(buttonName[i]);
// button[i].addActionListener(listener);
panel2.add(button[i],direct[i]);
}
add(panel2);
}
}
public class Test{
public static void main(String args[]){
MyJFrame myJFrame=new MyJFrame("我的窗口",100,100,800,800);
}
}
class PoliceListen implements ActionListener {
JTextField textInput;
String texString=null;
JButton button[]=new JButton[5];
public void setJTextField(JTextField text) {
textInput = text;
}
public void setJButton(JButton[] jb)
{
button=jb ;
}
public void actionPerformed(ActionEvent e) {
textInput.setText(null);
try{
boolean bool=false;
for(int i=0;i<5&&(!bool);i++){
if(e.getSource().equals(button[i])){
textInput.setText(button[i].getText());
bool=true;
}
}
}
catch(Exception ee) {
textInput.setText(ee.toString());
}
}
} 展开
import static javax.swing.JFrame.*;
import java.awt.*;
class MyJFrame extends JFrame{
JPanel panel1=new JPanel();
JPanel panel2=new JPanel();
JTextField textfield=new JTextField(10);
JButton button[]=new JButton[5];
//PoliceListen listener;
String buttonName[]={"北","南","西","东","中"};
String direct[]={BorderLayout.NORTH,BorderLayout.SOUTH,BorderLayout.WEST,BorderLayout.EAST,BorderLayout.CENTER };
MyJFrame(String s,int x,int y,int w,int h){
setLayout(new GridLayout(2,1));
addComponent();
setTitle(s);
setBounds(x,y,w,h);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
}
void addComponent(){
panel1.add(textfield);
add(panel1);
panel2.setLayout(new BorderLayout());
// listener=new PoliceListen();
// listener.setJTextField(textfield);
//listener.setJButton(button);
for(int i=0;i<5;i++){
button[i]=new JButton(buttonName[i]);
// button[i].addActionListener(listener);
panel2.add(button[i],direct[i]);
}
add(panel2);
}
}
public class Test{
public static void main(String args[]){
MyJFrame myJFrame=new MyJFrame("我的窗口",100,100,800,800);
}
}
class PoliceListen implements ActionListener {
JTextField textInput;
String texString=null;
JButton button[]=new JButton[5];
public void setJTextField(JTextField text) {
textInput = text;
}
public void setJButton(JButton[] jb)
{
button=jb ;
}
public void actionPerformed(ActionEvent e) {
textInput.setText(null);
try{
boolean bool=false;
for(int i=0;i<5&&(!bool);i++){
if(e.getSource().equals(button[i])){
textInput.setText(button[i].getText());
bool=true;
}
}
}
catch(Exception ee) {
textInput.setText(ee.toString());
}
}
} 展开
2个回答
推荐于2017-10-06
展开全部
import javax.swing.*;
import javax.swing.JFrame.*;
import java.awt.*;
import java.awt.event.*;
class DongNanXiBei extends JFrame{
JPanel panel1=new JPanel();
JPanel panel2=new JPanel();
JTextField textfield=new JTextField(10);
JButton button[]=new JButton[5];
//PoliceListen listener;
String buttonName[]={"北","南","西","东","中"};
String direct[]={BorderLayout.NORTH,BorderLayout.SOUTH,BorderLayout.WEST,BorderLayout.EAST,BorderLayout.CENTER };
DongNanXiBei(String s,int x,int y,int w,int h){
setLayout(new GridLayout(2,1));
addComponent();
setTitle(s);
setBounds(x,y,w,h);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
}
void addComponent(){
panel1.add(textfield);
add(panel1);
panel2.setLayout(new BorderLayout());
// listener=new PoliceListen();
// listener.setJTextField(textfield);
//listener.setJButton(button);
for(int i=0;i<5;i++){
button[i]=new JButton(buttonName[i]);
// button[i].addActionListener(listener);
panel2.add(button[i],direct[i]);
}
add(panel2);
}
public static void main(String args[]){
DongNanXiBei myJFrame=new DongNanXiBei("我的窗口",100,100,800,800);
}
class PoliceListen implements ActionListener {
JTextField textInput;
String texString=null;
JButton button[]=new JButton[5];
public void setJTextField(JTextField text) {
textInput = text;
}
public void setJButton(JButton[] jb)
{
button=jb ;
}
public void actionPerformed(ActionEvent e) {
textInput.setText(null);
try{
boolean bool=false;
for(int i=0;i<5&&(!bool);i++){
if(e.getSource().equals(button[i])){
textInput.setText(button[i].getText());
bool=true;
}
}
}catch(Exception ee) {
textInput.setText(ee.toString());
}
}
}
}
不好意思,为了我调试方便,类名改了一下。
import javax.swing.JFrame.*;
import java.awt.*;
import java.awt.event.*;
class DongNanXiBei extends JFrame{
JPanel panel1=new JPanel();
JPanel panel2=new JPanel();
JTextField textfield=new JTextField(10);
JButton button[]=new JButton[5];
//PoliceListen listener;
String buttonName[]={"北","南","西","东","中"};
String direct[]={BorderLayout.NORTH,BorderLayout.SOUTH,BorderLayout.WEST,BorderLayout.EAST,BorderLayout.CENTER };
DongNanXiBei(String s,int x,int y,int w,int h){
setLayout(new GridLayout(2,1));
addComponent();
setTitle(s);
setBounds(x,y,w,h);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
}
void addComponent(){
panel1.add(textfield);
add(panel1);
panel2.setLayout(new BorderLayout());
// listener=new PoliceListen();
// listener.setJTextField(textfield);
//listener.setJButton(button);
for(int i=0;i<5;i++){
button[i]=new JButton(buttonName[i]);
// button[i].addActionListener(listener);
panel2.add(button[i],direct[i]);
}
add(panel2);
}
public static void main(String args[]){
DongNanXiBei myJFrame=new DongNanXiBei("我的窗口",100,100,800,800);
}
class PoliceListen implements ActionListener {
JTextField textInput;
String texString=null;
JButton button[]=new JButton[5];
public void setJTextField(JTextField text) {
textInput = text;
}
public void setJButton(JButton[] jb)
{
button=jb ;
}
public void actionPerformed(ActionEvent e) {
textInput.setText(null);
try{
boolean bool=false;
for(int i=0;i<5&&(!bool);i++){
if(e.getSource().equals(button[i])){
textInput.setText(button[i].getText());
bool=true;
}
}
}catch(Exception ee) {
textInput.setText(ee.toString());
}
}
}
}
不好意思,为了我调试方便,类名改了一下。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的问题是什么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询