java怎么设置工具栏
JAVA怎么用代码实现播放器下面的一排工具栏用什么方法解决最好用代码表示下谢谢!!!JPanellabel3=newJPanel();label3.setLayout(n...
JAVA怎么用代码实现播放器下面的一排工具栏用什么方法解决最好用代码表示下 谢谢!!!
JPanel label3=new JPanel();
label3.setLayout(new BorderLayout());
label3.add(new JPanel(), BorderLayout.SOUTH);
JButton play2 = new JButton(new ImageIcon("按钮"));
play2.setSize(45,45);
play2.setLocation(0,13);
label3.add(play2);
为什么我这样仍然不能把play2 按钮添加到BorderLayout中该怎么办啊急用回答正确者追加50分谢谢!!! 展开
JPanel label3=new JPanel();
label3.setLayout(new BorderLayout());
label3.add(new JPanel(), BorderLayout.SOUTH);
JButton play2 = new JButton(new ImageIcon("按钮"));
play2.setSize(45,45);
play2.setLocation(0,13);
label3.add(play2);
为什么我这样仍然不能把play2 按钮添加到BorderLayout中该怎么办啊急用回答正确者追加50分谢谢!!! 展开
展开全部
private JMenuBar createJMenuBar(Action[] actions){//创建菜单栏
JMenuBar menubar = new JMenuBar(); //实例化菜单栏
JMenu menuFile = new JMenu("文件");
JMenu menuAbout = new JMenu("帮助");
menuAbout.add(new JMenuItem(actions[0]));
menuFile.add(new JMenuItem(actions[1]));
menubar.add(menuFile); //增加菜单
menubar.add(menuAbout);
return menubar;
}
private JToolBar createJToolBar(Action[] actions){//创建工具条
JToolBar toolBar = new JToolBar();//实例化工具条
for(int i=0; i< actions.length;i++){
JButton bt = new JButton(actions[i]);
bt.setRequestFocusEnabled(false);
//设置不需要焦点
toolBar.add(bt);//增加按钮到工具栏
}
return toolBar; //返回工具栏
}
//以下是我做项目的完整代码,你参考一下
/**************************************
* Title: 数据库综合操作
* Description: text类
* date : 2008-7-22
* author : yangcong
***************************************/
package framejava;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.text.*;
//简单的文本编辑器
public class mainframe extends JFrame{
JPanel textPane = new JPanel(); //文本窗格,编辑窗口
JLabel statusBar = new JLabel("JAVA综合操作平台V1.1 杨聪制作"); //状态栏
JFileChooser filechooser = new JFileChooser();//文本选择器
JButton shujuku = new JButton("数据库操作");
JButton wangluo = new JButton("网络操作");
JButton about = new JButton(" 关 于 ");
JButton exit = new JButton(" 退 出 ");
public mainframe(){ //构造函数
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setTitle("JAVA综合操作平台V1.1"); //调用父类构造函数
Action[] actions={ //Action数组,各种操作命令
new AboutAction(),
new ExitAction()
};
textPane.add(shujuku);
textPane.add(wangluo);
textPane.add(about);
textPane.add(exit);
/***********************************************************************/
shujuku.addActionListener(new mainframe_shujuku_actionAdapter(this));
shujuku.setSelected(true);
/***********************************************************************/
/***********************************************************************/
wangluo.addActionListener(new mainframe_wangluo_actionAdapter(this));
wangluo.setSelected(true);
/***********************************************************************/
about.addActionListener(actions[0]);
exit.addActionListener(actions[1]);
statusBar.setForeground(Color.red);
setJMenuBar(createJMenuBar(actions));
Container container= getContentPane();
container.add(createJToolBar(actions),BorderLayout.NORTH);
container.add(textPane,BorderLayout.CENTER);
container.add(statusBar,BorderLayout.SOUTH);
// mainframe m_view = new mainframe();
// m_view.pack();
// Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
// Dimension frameSize = m_view.getSize();
// if (frameSize.height > screenSize.height) {
// frameSize.height = screenSize.height;
// }
// if (frameSize.width > screenSize.width) {
// frameSize.width = screenSize.width;
// }
// m_view.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
//
// m_view.setSize(260,200);
// m_view.setVisible(true);
setSize(260,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//关闭窗口时退出程序
}
private JMenuBar createJMenuBar(Action[] actions){//创建菜单栏
JMenuBar menubar = new JMenuBar(); //实例化菜单栏
JMenu menuFile = new JMenu("文件");
JMenu menuAbout = new JMenu("帮助");
menuAbout.add(new JMenuItem(actions[0]));
menuFile.add(new JMenuItem(actions[1]));
menubar.add(menuFile); //增加菜单
menubar.add(menuAbout);
return menubar;
}
private JToolBar createJToolBar(Action[] actions){//创建工具条
JToolBar toolBar = new JToolBar();//实例化工具条
for(int i=0; i< actions.length;i++){
JButton bt = new JButton(actions[i]);
bt.setRequestFocusEnabled(false);
//设置不需要焦点
toolBar.add(bt);//增加按钮到工具栏
}
return toolBar; //返回工具栏
}
/**************************数据库动作操作*************************************/
void shujuku_actionPerformed(ActionEvent e) {
shujuku.setSelected(false);
datamainframe d_view = new datamainframe();
d_view.pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = d_view.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
d_view.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
d_view.setSize(270,190);
d_view.setVisible(true);
}
class mainframe_shujuku_actionAdapter
implements java.awt.event.ActionListener {
mainframe adaptee;
mainframe_shujuku_actionAdapter(mainframe adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.shujuku_actionPerformed(e);
}
}
/***********************************************************************/
/********************网络动作操作**************************************/
void wangluo_actionPerformed(ActionEvent e) {
wangluo.setSelected(false);
netview n_view = new netview();
n_view.pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = n_view.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
n_view.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
n_view.setSize(800,700);
n_view.setVisible(true);
}
class mainframe_wangluo_actionAdapter
implements java.awt.event.ActionListener {
mainframe adaptee;
mainframe_wangluo_actionAdapter(mainframe adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.wangluo_actionPerformed(e);
}
}
/***********************************************************************/
class ExitAction extends AbstractAction{ //退出命令
public ExitAction(){
super("退出");
}
public void actionPerformed(ActionEvent e){
System.exit(0);
}
}
class AboutAction extends AbstractAction{//关于选项命令
public AboutAction(){
super("关于");
}
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(mainframe.this,"JAVA综合操作平台V1.1\n"+"杨聪制作");
}
}
public static void main(String args[]){
new mainframe();
}
}
JMenuBar menubar = new JMenuBar(); //实例化菜单栏
JMenu menuFile = new JMenu("文件");
JMenu menuAbout = new JMenu("帮助");
menuAbout.add(new JMenuItem(actions[0]));
menuFile.add(new JMenuItem(actions[1]));
menubar.add(menuFile); //增加菜单
menubar.add(menuAbout);
return menubar;
}
private JToolBar createJToolBar(Action[] actions){//创建工具条
JToolBar toolBar = new JToolBar();//实例化工具条
for(int i=0; i< actions.length;i++){
JButton bt = new JButton(actions[i]);
bt.setRequestFocusEnabled(false);
//设置不需要焦点
toolBar.add(bt);//增加按钮到工具栏
}
return toolBar; //返回工具栏
}
//以下是我做项目的完整代码,你参考一下
/**************************************
* Title: 数据库综合操作
* Description: text类
* date : 2008-7-22
* author : yangcong
***************************************/
package framejava;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.text.*;
//简单的文本编辑器
public class mainframe extends JFrame{
JPanel textPane = new JPanel(); //文本窗格,编辑窗口
JLabel statusBar = new JLabel("JAVA综合操作平台V1.1 杨聪制作"); //状态栏
JFileChooser filechooser = new JFileChooser();//文本选择器
JButton shujuku = new JButton("数据库操作");
JButton wangluo = new JButton("网络操作");
JButton about = new JButton(" 关 于 ");
JButton exit = new JButton(" 退 出 ");
public mainframe(){ //构造函数
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setTitle("JAVA综合操作平台V1.1"); //调用父类构造函数
Action[] actions={ //Action数组,各种操作命令
new AboutAction(),
new ExitAction()
};
textPane.add(shujuku);
textPane.add(wangluo);
textPane.add(about);
textPane.add(exit);
/***********************************************************************/
shujuku.addActionListener(new mainframe_shujuku_actionAdapter(this));
shujuku.setSelected(true);
/***********************************************************************/
/***********************************************************************/
wangluo.addActionListener(new mainframe_wangluo_actionAdapter(this));
wangluo.setSelected(true);
/***********************************************************************/
about.addActionListener(actions[0]);
exit.addActionListener(actions[1]);
statusBar.setForeground(Color.red);
setJMenuBar(createJMenuBar(actions));
Container container= getContentPane();
container.add(createJToolBar(actions),BorderLayout.NORTH);
container.add(textPane,BorderLayout.CENTER);
container.add(statusBar,BorderLayout.SOUTH);
// mainframe m_view = new mainframe();
// m_view.pack();
// Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
// Dimension frameSize = m_view.getSize();
// if (frameSize.height > screenSize.height) {
// frameSize.height = screenSize.height;
// }
// if (frameSize.width > screenSize.width) {
// frameSize.width = screenSize.width;
// }
// m_view.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
//
// m_view.setSize(260,200);
// m_view.setVisible(true);
setSize(260,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//关闭窗口时退出程序
}
private JMenuBar createJMenuBar(Action[] actions){//创建菜单栏
JMenuBar menubar = new JMenuBar(); //实例化菜单栏
JMenu menuFile = new JMenu("文件");
JMenu menuAbout = new JMenu("帮助");
menuAbout.add(new JMenuItem(actions[0]));
menuFile.add(new JMenuItem(actions[1]));
menubar.add(menuFile); //增加菜单
menubar.add(menuAbout);
return menubar;
}
private JToolBar createJToolBar(Action[] actions){//创建工具条
JToolBar toolBar = new JToolBar();//实例化工具条
for(int i=0; i< actions.length;i++){
JButton bt = new JButton(actions[i]);
bt.setRequestFocusEnabled(false);
//设置不需要焦点
toolBar.add(bt);//增加按钮到工具栏
}
return toolBar; //返回工具栏
}
/**************************数据库动作操作*************************************/
void shujuku_actionPerformed(ActionEvent e) {
shujuku.setSelected(false);
datamainframe d_view = new datamainframe();
d_view.pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = d_view.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
d_view.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
d_view.setSize(270,190);
d_view.setVisible(true);
}
class mainframe_shujuku_actionAdapter
implements java.awt.event.ActionListener {
mainframe adaptee;
mainframe_shujuku_actionAdapter(mainframe adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.shujuku_actionPerformed(e);
}
}
/***********************************************************************/
/********************网络动作操作**************************************/
void wangluo_actionPerformed(ActionEvent e) {
wangluo.setSelected(false);
netview n_view = new netview();
n_view.pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = n_view.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
n_view.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
n_view.setSize(800,700);
n_view.setVisible(true);
}
class mainframe_wangluo_actionAdapter
implements java.awt.event.ActionListener {
mainframe adaptee;
mainframe_wangluo_actionAdapter(mainframe adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.wangluo_actionPerformed(e);
}
}
/***********************************************************************/
class ExitAction extends AbstractAction{ //退出命令
public ExitAction(){
super("退出");
}
public void actionPerformed(ActionEvent e){
System.exit(0);
}
}
class AboutAction extends AbstractAction{//关于选项命令
public AboutAction(){
super("关于");
}
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(mainframe.this,"JAVA综合操作平台V1.1\n"+"杨聪制作");
}
}
public static void main(String args[]){
new mainframe();
}
}
参考资料: 无
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询