JAVA swing怎么加入文本框
packagelab14;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassT...
package lab14;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextEditorFrame extends JFrame {
JMenuItem jMenuFileNew,jMenuFileOpen,jMenuFileSave,jMenuFileExit;//声明“文件”菜单的菜单项
JMenuItem jMenuFilecancel,jMenurecover,jMenucopy,jMenucut
,jMenuzhantie,jMenufont,jMenubackground,jMenufore;
JMenuItem jMenuHelpAbout;//声明“帮助”菜单的菜单项
public TextEditorFrame() {//初始化代码
super("文本编辑器");
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){}
Container c=this.getContentPane() ;
c.setLayout(new BorderLayout());
Icon newIcn=new ImageIcon("images/1.gif");
Icon openIcn=new ImageIcon("images/2.gif");
Icon saveIcn=new ImageIcon("images/3.gif");
Icon copyIcn=new ImageIcon("images/4.gif");
Icon cutIcn=new ImageIcon("images/4.gif");
Icon zhantieIcn=new ImageIcon("images/4.gif");
Icon helpIcn=new ImageIcon("images/5.gif");
//定义菜单条
JMenuBar jMenuBar1 = new JMenuBar();//定义菜单栏
//定义3个菜单
JMenu jMenuFile = new JMenu("文件");
JMenu jMenuEdit = new JMenu("编辑");
JMenu jMenuHelp = new JMenu("帮助");
// 初始化"文件"菜单的菜单项
jMenuFileNew = new JMenuItem("新建",newIcn);
jMenuFileOpen = new JMenuItem("打开",openIcn);
jMenuFileSave = new JMenuItem("保存",saveIcn);
jMenuFileExit = new JMenuItem("退出");
// 初始化"编辑"菜单的菜单项
jMenuFilecancel = new JMenuItem("撤销");
jMenurecover = new JMenuItem("恢复");
jMenucopy = new JMenuItem("复制",copyIcn);
jMenucut = new JMenuItem("剪切",cutIcn);
jMenuzhantie = new JMenuItem("粘贴",zhantieIcn);
jMenufont = new JMenuItem("字体");
jMenubackground = new JMenuItem("设置前景颜色");
jMenufore = new JMenuItem("设置背景颜色");
// 初始化"帮助"菜单的菜单项
jMenuHelpAbout = new JMenuItem("关于...",helpIcn);
//把菜单项添加到“文件”菜单
jMenuFile.add(jMenuFileNew);
jMenuFile.add(jMenuFileOpen);
jMenuFile.add(jMenuFileSave);
jMenuFile.addSeparator();//添加一条分隔线
jMenuFile.add(jMenuFileExit);
//把菜单项添加到“编辑”菜单
jMenuEdit.add(jMenuFilecancel);
jMenuEdit.add(jMenurecover);
jMenuEdit.add(jMenucopy);
jMenuEdit.add(jMenucut);
jMenuEdit.add(jMenuzhantie);
jMenuEdit.add(jMenufont);
jMenuEdit.add(jMenubackground);
jMenuEdit.add(jMenufore);
//把菜单项添加到“帮助”菜单
jMenuHelp.add(jMenuHelpAbout);
//把3个菜单添加到菜单条
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenuEdit);
jMenuBar1.add(jMenuHelp);
//把菜单系统添加到框架JFrame容器中
this.setJMenuBar(jMenuBar1);
this.setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new TextEditorFrame();
}
} 展开
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextEditorFrame extends JFrame {
JMenuItem jMenuFileNew,jMenuFileOpen,jMenuFileSave,jMenuFileExit;//声明“文件”菜单的菜单项
JMenuItem jMenuFilecancel,jMenurecover,jMenucopy,jMenucut
,jMenuzhantie,jMenufont,jMenubackground,jMenufore;
JMenuItem jMenuHelpAbout;//声明“帮助”菜单的菜单项
public TextEditorFrame() {//初始化代码
super("文本编辑器");
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){}
Container c=this.getContentPane() ;
c.setLayout(new BorderLayout());
Icon newIcn=new ImageIcon("images/1.gif");
Icon openIcn=new ImageIcon("images/2.gif");
Icon saveIcn=new ImageIcon("images/3.gif");
Icon copyIcn=new ImageIcon("images/4.gif");
Icon cutIcn=new ImageIcon("images/4.gif");
Icon zhantieIcn=new ImageIcon("images/4.gif");
Icon helpIcn=new ImageIcon("images/5.gif");
//定义菜单条
JMenuBar jMenuBar1 = new JMenuBar();//定义菜单栏
//定义3个菜单
JMenu jMenuFile = new JMenu("文件");
JMenu jMenuEdit = new JMenu("编辑");
JMenu jMenuHelp = new JMenu("帮助");
// 初始化"文件"菜单的菜单项
jMenuFileNew = new JMenuItem("新建",newIcn);
jMenuFileOpen = new JMenuItem("打开",openIcn);
jMenuFileSave = new JMenuItem("保存",saveIcn);
jMenuFileExit = new JMenuItem("退出");
// 初始化"编辑"菜单的菜单项
jMenuFilecancel = new JMenuItem("撤销");
jMenurecover = new JMenuItem("恢复");
jMenucopy = new JMenuItem("复制",copyIcn);
jMenucut = new JMenuItem("剪切",cutIcn);
jMenuzhantie = new JMenuItem("粘贴",zhantieIcn);
jMenufont = new JMenuItem("字体");
jMenubackground = new JMenuItem("设置前景颜色");
jMenufore = new JMenuItem("设置背景颜色");
// 初始化"帮助"菜单的菜单项
jMenuHelpAbout = new JMenuItem("关于...",helpIcn);
//把菜单项添加到“文件”菜单
jMenuFile.add(jMenuFileNew);
jMenuFile.add(jMenuFileOpen);
jMenuFile.add(jMenuFileSave);
jMenuFile.addSeparator();//添加一条分隔线
jMenuFile.add(jMenuFileExit);
//把菜单项添加到“编辑”菜单
jMenuEdit.add(jMenuFilecancel);
jMenuEdit.add(jMenurecover);
jMenuEdit.add(jMenucopy);
jMenuEdit.add(jMenucut);
jMenuEdit.add(jMenuzhantie);
jMenuEdit.add(jMenufont);
jMenuEdit.add(jMenubackground);
jMenuEdit.add(jMenufore);
//把菜单项添加到“帮助”菜单
jMenuHelp.add(jMenuHelpAbout);
//把3个菜单添加到菜单条
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenuEdit);
jMenuBar1.add(jMenuHelp);
//把菜单系统添加到框架JFrame容器中
this.setJMenuBar(jMenuBar1);
this.setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new TextEditorFrame();
}
} 展开
1个回答
展开全部
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class MyJFrame {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame mainFrame = new JFrame("Cool TextField");
mainFrame.setLayout(null);
JButton jb = new JButton("ce");
JTextField jf = new JTextField();
jb.setBounds(80, 0, 20, 30);
jb.setVisible(true);
jf.setVisible(true);
jf.add(jb);
jf.setBounds(5, 50, 100, 30);
mainFrame.getContentPane().add(jf);
mainFrame.pack();
mainFrame.setVisible(true);
mainFrame.setBounds(100, 100, 200, 200);
}
}
import javax.swing.JFrame;
import javax.swing.JTextField;
public class MyJFrame {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame mainFrame = new JFrame("Cool TextField");
mainFrame.setLayout(null);
JButton jb = new JButton("ce");
JTextField jf = new JTextField();
jb.setBounds(80, 0, 20, 30);
jb.setVisible(true);
jf.setVisible(true);
jf.add(jb);
jf.setBounds(5, 50, 100, 30);
mainFrame.getContentPane().add(jf);
mainFrame.pack();
mainFrame.setVisible(true);
mainFrame.setBounds(100, 100, 200, 200);
}
}
追问
能在我的代码那里加吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询