新手提问

hebsxl2000 2010-06-05 09:09:39
JToolBar 怎样指定工具条方向 ?
JPanel 怎么传图片?
初学者 希望帮写下代码 非常感谢
...全文
110 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
24K純帥 2010-06-05
  • 打赏
  • 举报
回复
别人的代码,LZ看看有收获木有
24K純帥 2010-06-05
  • 打赏
  • 举报
回复

import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;

import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JPanel;

import java.awt.*;
import java.awt.event.*;

public class ToolBarDemo extends JFrame {
protected JTextArea textArea;
protected String newline = "\n ";

public ToolBarDemo() {
//Do frame stuff.
super( "ToolBarDemo ");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

//Create the toolbar.
JToolBar toolBar = new JToolBar();
addButtons(toolBar);

//Create the text area used for output.
textArea = new JTextArea(5, 30);
JScrollPane scrollPane = new JScrollPane(textArea);

//Lay out the content pane.
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
contentPane.setPreferredSize(new Dimension(400, 100));
contentPane.add(toolBar, BorderLayout.NORTH);
contentPane.add(scrollPane, BorderLayout.CENTER);
setContentPane(contentPane);
}

protected void addButtons(JToolBar toolBar) {
JButton button = null;

//first button
button = new JButton(new ImageIcon( "images/left.gif "));
button.setToolTipText( "This is the left button ");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
displayResult( "Action for first button ");
}
});
toolBar.add(button);

//second button
button = new JButton(new ImageIcon( "images/middle.gif "));
button.setToolTipText( "This is the middle button ");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
displayResult( "Action for second button ");
}
});
toolBar.add(button);

//third button
button = new JButton(new ImageIcon( "images/right.gif "));
button.setToolTipText( "This is the right button ");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
displayResult( "Action for third button ");
}
});
toolBar.add(button);
}

protected void displayResult(String actionDescription) {
textArea.append(actionDescription + newline);
}

public static void main(String[] args) {
ToolBarDemo frame = new ToolBarDemo();
frame.pack();
frame.setVisible(true);
}
}
岁月之梦 2010-06-05
  • 打赏
  • 举报
回复
都做web方面的东西了 这个真忘记了 帮你顶

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧