java图像编程
第一排:从1到5,自增然后再自减;
第二排:(空一格)从1到4,自增然后再自减;
第三排:(空两格)从1到3,自增然后再自减;
。。。。以此类推,规律已经帮你找出来了,自己想办法看如何简单实现他??程序猿还是要自己动动脑子,不然不会成长的
㈡ java图像编程
思路很简单,设置按钮的监听器,你认真看一下监听器的教程。比如你设置一个按钮B,然后给B加上一个监听器,当按下B的时候跳转到另一个窗口,看下面代码实现了一个简单跳转!希望能帮到你。
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MultiListener {
private Frame f = new Frame("测试");
private Frame f1 = new Frame("另一个窗口");
private TextArea ta = new TextArea(6 , 40);
private Button b1 = new Button("按钮一");
private Button b2 = new Button("按钮二");
public void init(){
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
f1.pack();
f1.setVisible(true);
}
});
f.add(ta);
Panel p = new Panel();
p.add(b1);
p.add(b2);
f.add(p , BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
}
㈢ java 编程 图像问题
用线程 Thread.sleep(1000); 楼上的都不可以额~
㈣ java 有关处理图象的编程(200分求教)
看来楼主也不是很急啊,做好了,在下面:
http://hi..com/ttbet/blog/item/ef2991f01a4390c47931aa81.html
==========================================================
//请将下面代码保存成:LineTest.java , 已在JDK1.4环境下测试通过
//如果你的JDK是:JDK1.6_10,请取消掉UI部分的注释,这将支持最新的UI:NimbusLookAndFeel
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.event.*;
//主程序
public class LineTest {
//程序入口
public static void main(String[] args) throws Exception{
// LookAndFeelInfo[] info = UIManager.getInstalledLookAndFeels();
// for(int i=0; i<info.length; i++){
// if("Nimbus".equals(info[i].getName()))
// UIManager.setLookAndFeel(info[i].getClassName());
// }
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame f = new JFrame("线条测试");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(800,600);
f.setLocationRelativeTo(null);
MyCanvas c=new MyCanvas();
f.getContentPane().add(c);
f.getContentPane().add(new MyPanel(c),"South");
f.setVisible(true);
}
}
/**这个面板装载了8个控制线条参数的滑块组件*/
class MyPanel extends JPanel implements ChangeListener{
public static int v1,v2,v3,v4,v5,v6,v7,v8;
private JSlider d1,d2,d3,d4,d5,d6,d7,d8;
private Canvas c;
MyPanel(Canvas c){
super(new GridLayout(2,3));
this.c=c;
this.setPreferredSize(new Dimension(1,120));
this.setBorder(BorderFactory.createRaisedBevelBorder());
d1=new JSlider(1,100,30);//组内纵向距离
d2=new JSlider(-500,500,100);//组纵向距离
d3=new JSlider(10,1000,222);//组横向距离
d4=new JSlider(0,100,8);//线条数量
d5=new JSlider(-100,800,168);//Y轴偏移
d6=new JSlider(2,100,10);//线条粗细度
d7=new JSlider(1,100,80);//线条淡入淡出程度
d8=new JSlider(0,255,50);//线条颜色
initSliders(d1,"D1距离");
initSliders(d2,"D2距离");
initSliders(d3,"D3距离");
initSliders(d4,"线条数量");
initSliders(d5,"Y轴向偏移");
initSliders(d6,"线条粗细");
initSliders(d7,"淡入淡出");
initSliders(d8,"线条对比度");
this.stateChanged(null);
}
private void initSliders(JSlider c,String title){
c.setBorder(BorderFactory.createTitledBorder(title));
c.addChangeListener(this);
this.add(c);
}
public void stateChanged(ChangeEvent e) {
v1=d1.getValue();
v2=d2.getValue();
v3=d3.getValue();
v4=d4.getValue();
v5=d5.getValue();
v6=d6.getValue();
v7=d7.getValue();
v8=d8.getValue();
c.paint(c.getGraphics());
}
}
/**这是画布类*/
class MyCanvas extends Canvas{
public void paint(Graphics g){
if(g==null)return;
int d1 = MyPanel.v1;
int d2 = MyPanel.v2;
int d3 = MyPanel.v3;
int w=this.getWidth();
int h=this.getHeight();
int a = MyPanel.v4;
int oy=MyPanel.v5;
//根据滑块参数来取得一个形状的对象
Shape shape = MyModel.getShape(d1, d2, d3, w, h,a,oy);
//使用缓冲区来作图,起到防止画布闪烁的目的
BufferedImage img = new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = img.createGraphics();
g2.setColor(Color.white);
g2.fillRect(0,0,w,h);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
//画布的笔触,粗细调节
Stroke stroke = new BasicStroke(MyPanel.v6/10f);
g2.setStroke(stroke);
float[] dist={0.0f,MyPanel.v7/100f};
Color[] colors = {new Color(0x00FFFFFF,true),new Color(MyPanel.v8,MyPanel.v8,MyPanel.v8)};
//画布的颜料,淡入淡出的效果
Paint paint = new LinearGradientPaint(new Point(0,0),new Point(w/2,0),dist,colors,MultipleGradientPaint.CycleMethod.REFLECT);
g2.setPaint(paint);
g2.draw(shape);
g2.dispose();
//将缓冲区图像画到画布上
g.drawImage(img,0,0,null);
g.dispose();
}
}
class MyModel{
/**
* 参数说明:<br/>
* d1组内线条的距离
* d2组之间的纵向距离
* d3组之间的横向距离
* w是画布的宽度
* h是画布的高度
* amount每组的线条数量
* offsetY线条Y轴向的偏移
* */
public static Shape getShape(int d1,int d2,int d3,int w,int h,int amount,int offsetY){
Path2D p = new Path2D.Double();
for(int i=0; i<amount; i++){
Path2D t = new Path2D.Double();
double x1=w/2d;
double y1=i*d1+offsetY;
double x2=x1;
double y2=y1-d2;
t.moveTo(0,y1);
t.lineTo(x1-d3/2d,y1);
t.curveTo(x1,y1,x2,y2,x2+d3/2d,y2);
t.lineTo(w,y2);
p.append(t,false);
}
return p;
}
}
㈤ 我用java的图像编程,怎么用repaint()函数是,原来的图像不消除啊下面是我的代码,原来的矩形还在哪里
在每次画矩形前,先设定一种背景颜色(如白色)来清除先前的客户区
g2.setBackground(new Color(255,255,255));
g2.clearRect(0, 0, width, height); (这里需要传入客户区的宽和高)
然后在进行你的步骤就可以实现你要的矩形移动效果了。
试试吧,有问题再讨论。
㈥ java图形编程
代码如下,以后做界面也建议你把内容画在一个 JPanel 上然后添加到 JFrame 里。
JFrame 的坐标是从整个窗口的左上角为原点的,包含了边框。因此我画在 JPanel 上,避免了这个问题。
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Color;
class MyPanel extends JPanel {
public void paint (Graphics g) {
super.paint(g);
g.setColor(Color.RED);
g.fillRect(30, 30, 200, 100);
g.setColor(Color.WHITE);
for (int i=1; i<5; i++) {
g.drawLine(30, 30+100*i/5, 230, 30+100*i/5);
}
for (int i=1; i<10; i++) {
g.drawLine(30+200*i/10, 30, 30+200*i/10, 130);
}
}
}
public class Demo extends JFrame {
public Demo () {
super("Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(260, 200);
setLocationRelativeTo(null);
setContentPane(new MyPanel());
setVisible(true);
}
public static void main (String args[]) {
new Demo();
}
}
㈦ Java图形用户界面编程
我给你写,已经测试,你看合不合你的意思
package dongzi.pattern;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class SumTest extends JPanel{
JTextField mem[] = new JTextField[10] ;
JButton sumButton = new JButton("SUM") ;
JTextField sumText = new JTextField(4) ;
public SumTest() {
setLayout(new FlowLayout()) ;
for (int i = 0; i < 10; i++) {
mem[i] = new JTextField(4) ;
add(mem[i]) ;
}
add(sumButton) ;
add(sumText) ;
sumButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int sum = 0 ;
for (int i = 0 ;i < 10; i++) {
sum += Integer.parseInt(mem[i].getText().trim()) ;
}
sumText.setText(String.valueOf(sum)) ;
}
}) ;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame = new JFrame() ;
SumTest test = new SumTest() ;
frame.add(test) ;
frame.setSize(800, 100) ;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
frame.setVisible(true) ;
}
}
㈧ java编程实现图形界面
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JButton;
public class mi
{
private static String username;
private static String password ;
private static JTextField []t={
new JTextField("账号:",8),new JTextField(10),
new JTextField("密码:",8),new JPasswordField(10)};
public static void main (String args[]){
JFrame app=new JFrame("账号密码演示程序");
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.setSize(280,120);
Container c=app.getContentPane();
c.setLayout(new FlowLayout());
t[0].setEditable(false);
t[2].setEditable(false);
for(int i=0;i<4;i++)
c.add(t[i]);t[1].setText("");
JButton[]b={new JButton("确定"),new JButton("重置")};
c.add(b[0]);c.add(b[1]);
app.setLocationRelativeTo(null);
app.setVisible(true);
b[1].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
t[1].setText("");
t[3].setText("");
}
});
// 登录按钮加事件监听器
b[0].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
username = t[1].getText();
password = t[3].getText();
//判断用户名密码是否正确
if (username.equals("数字") && password.equals("123")) {
JOptionPane.showMessageDialog(null, "登陆成功!", "消息",
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误!", "错误",
JOptionPane.ERROR_MESSAGE);
}
}
}); }
}
㈨ java图形界面编程
执行java Applt小程序不是这样运行的。你必须建一个html文件,然后在输入
<applet code="ButtonDemo.class"
width=320 height=180>
</applet>
其中code是你编译ButtonDemo类是生成的class文件。然后在cmd中找到html文件所在的路径下输入appletviewer xxx.html
就可以运行了