显示文本框
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.image.*;
public class ScrollingImage extends JFrame implements ActionListener
{ private ImageIcon colorVersion = null ;
private ImageIcon grayVersion = null ;
private BufferedImage originalImage = null;
private JLabel imageLabel = new JLabel();
private JButton quit = new JButton("Quit");
private JButton gray= new JButton("Gray");
private JButton recover= new JButton("Recover");
private JButton shrink= new JButton("Shrink");
private String fileName = "scenery.jpg";
public ScrollingImage()
{
super ("Scrolling Image");
Image colorImage = getToolkit().getImage("scenery.jpg");
Image grayImage = createImage(new FilteredImageSource(
colorImage.getSource(),new GrayFilter(true,50)));
colorVersion=new ImageIcon(colorImage);
grayVersion=new ImageIcon(grayImage);
ImageIcon icon = new ImageIcon(fileName);
imageLabel.setIcon(icon);
JScrollPane scrollingLabel = new JScrollPane(imageLabel);
scrollingLabel.setPreferredSize(new Dimension(500,400));
JPanel info =new JPanel(new GridLayout(4,1));
info.add(new JLabel("image Name: "+fileName));
info.add(new JLabel("Initial image Width: "+icon.getIconWidth()));
info.add(new JLabel("Initial image Height: "+icon.getIconHeight()));
info.add(new JLabel("scrollPane Dimension: "+"500,400"));
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,scrollingLabel,info);
split.setDividerSize(5);
split.setOneTouchExpandable(true);
split.setContinuousLayout(true);
JPanel buttons = new JPanel(new FlowLayout());
buttons.add(quit);
buttons.add(gray);
buttons.add(recover);
buttons.add(shrink);
getContentPane().add("Center",split);
getContentPane().add("South",buttons);
quit.addActionListener(this);
gray.addActionListener(this);
recover.addActionListener(this);
shrink.addActionListener(this);
imageLabel .setIcon(colorVersion);
validate();pack();setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{ if (ae.getSource()==quit)
System.exit(0);
if(ae.getSource()==recover)
imageLabel.setIcon(colorVersion);
if(ae.getSource()==gray)
imageLabel.setIcon(grayVersion);
else if(ae.getSource()==shrink)
{ }
}
public static void main (String args[])
{
ScrollingImage sti = new ScrollingImage();
}
}放缩
import javax.swing.*; import java.awt.*;
import java.awt.event.*; class C extends JFrame
{
public static void main(String[] args)
{ new C(); } public C()
{
final JLabel imgView = new JLabel(new ImageIcon("scenery.jpg"))
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawImage(((ImageIcon)getIcon()).getImage(), 0, 0, getWidth(), getHeight(), null);
}
};
addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
double zoomFactor = e.getKeyCode() == KeyEvent.VK_UP ? 1.1 :
e.getKeyCode() == KeyEvent.VK_DOWN ? .9 : 1;
imgView.setSize((int)(imgView.getWidth() * zoomFactor),
(int)(imgView.getHeight() * zoomFactor));
}
});
add(imgView);
setSize(800, 600);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.image.*;
public class ScrollingImage extends JFrame implements ActionListener
{ private ImageIcon colorVersion = null ;
private ImageIcon grayVersion = null ;
private BufferedImage originalImage = null;
private JLabel imageLabel = new JLabel();
private JButton quit = new JButton("Quit");
private JButton gray= new JButton("Gray");
private JButton recover= new JButton("Recover");
private JButton shrink= new JButton("Shrink");
private String fileName = "scenery.jpg";
public ScrollingImage()
{
super ("Scrolling Image");
Image colorImage = getToolkit().getImage("scenery.jpg");
Image grayImage = createImage(new FilteredImageSource(
colorImage.getSource(),new GrayFilter(true,50)));
colorVersion=new ImageIcon(colorImage);
grayVersion=new ImageIcon(grayImage);
ImageIcon icon = new ImageIcon(fileName);
imageLabel.setIcon(icon);
JScrollPane scrollingLabel = new JScrollPane(imageLabel);
scrollingLabel.setPreferredSize(new Dimension(500,400));
JPanel info =new JPanel(new GridLayout(4,1));
info.add(new JLabel("image Name: "+fileName));
info.add(new JLabel("Initial image Width: "+icon.getIconWidth()));
info.add(new JLabel("Initial image Height: "+icon.getIconHeight()));
info.add(new JLabel("scrollPane Dimension: "+"500,400"));
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,scrollingLabel,info);
split.setDividerSize(5);
split.setOneTouchExpandable(true);
split.setContinuousLayout(true);
JPanel buttons = new JPanel(new FlowLayout());
buttons.add(quit);
buttons.add(gray);
buttons.add(recover);
buttons.add(shrink);
getContentPane().add("Center",split);
getContentPane().add("South",buttons);
quit.addActionListener(this);
gray.addActionListener(this);
recover.addActionListener(this);
shrink.addActionListener(this);
imageLabel .setIcon(colorVersion);
validate();pack();setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{ if (ae.getSource()==quit)
System.exit(0);
if(ae.getSource()==recover)
imageLabel.setIcon(colorVersion);
if(ae.getSource()==gray)
imageLabel.setIcon(grayVersion);
else if(ae.getSource()==shrink)
{ }
}
public static void main (String args[])
{
ScrollingImage sti = new ScrollingImage();
}
}放缩
import javax.swing.*; import java.awt.*;
import java.awt.event.*; class C extends JFrame
{
public static void main(String[] args)
{ new C(); } public C()
{
final JLabel imgView = new JLabel(new ImageIcon("scenery.jpg"))
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawImage(((ImageIcon)getIcon()).getImage(), 0, 0, getWidth(), getHeight(), null);
}
};
addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
double zoomFactor = e.getKeyCode() == KeyEvent.VK_UP ? 1.1 :
e.getKeyCode() == KeyEvent.VK_DOWN ? .9 : 1;
imgView.setSize((int)(imgView.getWidth() * zoomFactor),
(int)(imgView.getHeight() * zoomFactor));
}
});
add(imgView);
setSize(800, 600);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
解决方案 »
- this
- 求助:一道华为面试题(关于类的初始化)
- Socket编程,不知道错那了,初学者,帮帮忙!开始启动后只能从发送一次信息,而且乱码,
- 求一个关于表格的Swing实现。即表格的一列为复选框,勾中的时候,表格的另一列要灰掉(区分行)。未选中时,表格另一列正常显示。
- 如何配置JAVA环境啊?
- 设置窗口可见的问题, setVisible(true);
- 【UML的问题】在通讯图(就是2.0的协作图里)如何对if-else建模?
- 写了一个连接Mysql数据库的程序,现在怎么打个jar包使用???
- 中国大学生java程序设计联盟筹备工作启动!!!!
- 请教:如何在Applet中得到某一点像素的颜色?
- 请问怎么改变java sound的音量?
- (求解)请简单构造一个“SQL注入”漏洞发生得场景,即编写一个有问题的SQL访问代码,并模拟可能存在的安全问题。
楼主【rpdou】截止到2008-07-21 10:06:16的历史汇总数据(不包括此帖):
发帖的总数量:1 发帖的总分数:0 每贴平均分数:0
回帖的总数量:0 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:1 未结的总分数:0
结贴的百分比:0.00 % 结分的百分比:---------------------
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html