
加一个panel或是JToolBar
------------------------------------------------------------
import java.awt.Dimension
import java.awt.Toolkit
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JProgressBar
import javax.swing.JToolBar
public class Table extends JFrame {
public Table() {
setResizable(false)
getContentPane().setLayout(null)
JToolBar toolBar = new JToolBar()
toolBar.add(new JLabel("state"))
toolBar.add(new JProgressBar())
toolBar.setFloatable(false)
toolBar.setBounds(0, 253, 454, 15)
getContentPane().add(toolBar)
// 窗口属性的设置
setDefaultCloseOperation(EXIT_ON_CLOSE)
setLocationRelativeTo(null)
setSize(460, 300)
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize()
setLocation((screenSize.width - getWidth()) / 2,
(screenSize.height - getHeight()) / 2)
setVisible(true)
}
public static void main(String[] args) {
new Table()
}
}
package guiimport java.awt.BorderLayout
import java.awt.Graphics2D
import java.awt.Image
import java.awt.RenderingHints
import java.awt.Toolkit
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import java.awt.image.BufferedImage
import javax.swing.ImageIcon
import javax.swing.JButton
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JPanel
public class Bean extends JFrame implements ActionListener {
JPanel jPanel
JLabel jLabel
Image image
ImageIcon imageIcon
JButton jButton
JButton jButton1
int w
int h
int f
public Bean() {
super("图片")
jButton = new JButton("变大")
jButton1 = new JButton("反转")
jButton.addActionListener(this)
jButton1.addActionListener(this)
image = Toolkit.getDefaultToolkit().getImage("src/img1.jpg")
jLabel = new JLabel()
jPanel = new JPanel()
ImageIcon imageIcon = new ImageIcon(image)
jLabel.setIcon(imageIcon)
jPanel.add(jLabel)
w = image.getWidth(jLabel)
h = image.getHeight(jLabel)
this.add(jPanel, BorderLayout.NORTH)
this.add(jButton, BorderLayout.SOUTH)
this.add(jButton1, BorderLayout.EAST)
this.setVisible(true)
this.setSize(600, 600)
}
public static void main(String[] args) {
new Bean()
}
public void big() {
w += 20
h += 20
BufferedImage bffimage = new BufferedImage(w, h,
BufferedImage.TYPE_3BYTE_BGR)
// 把图片读到bufferedImage中
bffimage.getGraphics().drawImage(image, 0, 0, w, h, null)
// 得到转换后的Image图片
Image realImage = bffimage
// 可以把图片转化为ImageIcon,(Swing中运用)
ImageIcon img = new ImageIcon(realImage)
jLabel.setIcon(img)
}
public void fz() {
BufferedImage bffimage = new BufferedImage(w, h,
BufferedImage.TYPE_3BYTE_BGR)
// 把图片读到bufferedImage中
bffimage.getGraphics().drawImage(image, 0, 0, w, h, null)
f+=45
// 得到转换后的Image图片
bffimage=rotateImage(bffimage, f)
Image realImage = bffimage
// 可以把图片转化为ImageIcon,(Swing中运用)
ImageIcon img = new ImageIcon(realImage)
jLabel.setIcon(img)
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jButton) {
big()
}
if (e.getSource() == jButton1) {
fz()
}
}
/**
* 旋转图片为指定角度
*
* @param bufferedimage
* 目标图像
* @param degree
* 旋转角度
* @return
*/
public static BufferedImage rotateImage(final BufferedImage bufferedimage,
final int degree) {
int w = bufferedimage.getWidth()
int h = bufferedimage.getHeight()
int type = bufferedimage.getColorModel().getTransparency()
BufferedImage img
Graphics2D graphics2d
(graphics2d = (img = new BufferedImage(w, h, type)).createGraphics())
.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR)
graphics2d.rotate(Math.toRadians(degree), w / 2, h / 2)
graphics2d.drawImage(bufferedimage, 0, 0, null)
graphics2d.dispose()
return img
}
}
不知道你的描述是否是你真正的需求,我这里提供有两种方法如下:1.你可以在主界面里设置一个轮询线程,定时1秒,或者半秒查询数据库,如果有变化就更新。
2.你可以使用Observer模式。可以使用JDK自带的PropertyChangeSupport这一接口来帮助实现Observer模式。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)