1.JAVAå°ç¨åºââââå¾ç®å
2.java:求一个用swing来做小程序,小程序源我是码j码用来修改配置文件用的,求代码谢谢
3.ä¸ä¸ªç»ç´çº¿çJAVAå°ç¨åº
JAVAå°ç¨åºââââå¾ç®å
import javax.swing.*;
import java.awt.event.*;
public class TestFrame extends JFrame,程序织梦分页源码implements ActionListner
{
public TestFrame()
{
JButton b = new JButton("exit");
b.addActionListener(this);
Container cp = this.getContentPane();
cp.add(b);
this.setSize(,);
this.setVisible(true);
}
public void actionPerformed(ActionEvent evt)
{
System.exit(0);
}
public static void main(String[] args)
{
new TestFrame();
}
}
java:求一个用swing来做小程序,我是源代用来修改配置文件用的,求代码谢谢
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class Test extends JFrame {
private JPanel jp = new JPanel();
private JButton jb = new JButton("按钮一");
private JButton jb = new JButton("按钮二");
private JButton jb = new JButton("按钮三");
private JButton[] jb = new JButton[] { jb,小程序源胜博棋牌源码 jb, jb };
private JLabel jl = new JLabel("请单击按钮!");
private int count = 0;
public Test() {
for (int i = 0; i < jb.length; i++) {
jp.add(jb[i]);
}
jp.add(jl);
this.add(jp);
this.setTitle("点按钮,码j码棋牌源码运营公司记录单击按钮的程序次数和名字!");
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Test.this.jl.setText(jl.getText());
}
});
for (int i = 0; i < jb.length; i++) {
jb[i].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == jb) {
Test.this.jl.setText("您单击的源代是按钮一,您总共单机了" + (++count)
+ "次按钮");
} else if (e.getSource() == jb) {
Test.this.jl.setText("您单击的小程序源是按钮二,您总共单机了" + (++count)
+ "次按钮");
} else if (e.getSource() == jb) {
Test.this.jl.setText("您单击的码j码是按钮三,您总共单机了" + (++count)
+ "次按钮");
}
}
});
this.setBounds(,程序 , , );
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
public static void main(String[] args) {
new Test();
}
}
ä¸ä¸ªç»ç´çº¿çJAVAå°ç¨åº
è¿æ¯æ以ååçä¸ä¸ªå¯ä»¥ç»å¤é¢è²å¤å¾å½¢çä¸è¥¿ï¼ç»ä½ çç..
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Map;
import javax.swing.*;
public class DrawBorder extends JFrame implements MouseListener,
MouseMotionListener {
// private JComboBox;
private JLabel label;
private JLabel labelColor;
private JLabel labelShape;
private String[] colors = { "Black", "Blue", "Green", "Cyan", "Gray",
"Orange", "Red" };
private String[] shapes = { "Line", "Rectangle", "Oval", "TDRectangle" };
private Map mpColor;
private JComboBox comboboxColor;
private JComboBox comboboxShape;
ArrayList lstShape;
protected int x1;
protected int y1;
protected int x2;
protected int y2;
protected String color;
private String shape;
public void display() {
shape = "Line";
comboboxShape = new JComboBox(shapes);
comboboxShape.setMaximumRowCount(shapes.length);
comboboxShape.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent event) {
// determine whether check box selected
if (event.getStateChange() == ItemEvent.SELECTED) {
shape = shapes[comboboxShape.getSelectedIndex()];
}
}
});
color = "BLACK";
comboboxColor = new JComboBox(colors);
comboboxColor.setMaximumRowCount(colors.length);
comboboxColor.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent event) {
if (event.getStateChange() == ItemEvent.SELECTED) {
color = colors[comboboxColor.getSelectedIndex()];
}
}
});
label = new JLabel();
labelShape = new JLabel("å¾å½¢:");
labelColor = new JLabel("é¢è²:");
label.setText(shape);
// getContentPane().add(label);
lstShape = new ArrayList();
Container container = getContentPane();
container.setLayout(new FlowLayout());
container.add(labelShape);
container.add(comboboxShape);
container.add(labelColor);
container.add(comboboxColor);
container.add(label);
getContentPane().setBackground(Color.WHITE);
addMouseListener(this);
addMouseMotionListener(this);
setSize(, );
setVisible(true);
}
public void mouseClicked(MouseEvent e) {
label.setText("åå»é¼ æ å¨: [" + e.getX() + ", " + e.getY() + "]");
}
public void mouseEntered(MouseEvent e) {
label.setText("é¼ æ å¨: [" + e.getX() + ", " + e.getY() + "]");
}
public void mouseExited(MouseEvent e) {
label.setText("é¼ æ å¨: [çªå£å¤]");
}
public void mousePressed(MouseEvent e) {
label.setText("æä½é¼ æ å¨: [" + e.getX() + ", " + e.getY() + "]");
x1 = e.getX();
y1 = e.getY();
}
public void mouseReleased(MouseEvent e) {
label.setText("æ¾å¼é¼ æ å¨: [" + e.getX() + ", " + e.getY() + "]");
// å¤ææ¯å¦æä½é¼ æ 并æå¨è¿ï¼å¦æä¸åä¸äº§çå¾å½¢
if (((x1 == 0 && y1 == 0) || (x2 == 0 && y2 == 0)) == false) {
if (this.shape.equals("Line")) {
lstShape.add(new Line(x1, y1, x2, y2, color));
}
else if (this.shape.equals("Rectangle")) {
if (x2 > x1 && y2 > y1) {
lstShape.add(new Rectangle(x1, y1, x2 - x1, y2 - y1, color));
}
else if (x2 < x1 && y2 > y1) {
lstShape.add(new Rectangle(x2, y1, x1 - x2, y2 - y1, color));
}
else if (x2 > x1 && y2 < y1) {
lstShape.add(new Rectangle(x1, y2, x2 - x1, y1 - y2, color));
}
else if (x2 < x1 && y2 < y1) {
lstShape.add(new Rectangle(x2, y2, x1 - x2, y1 - y2, color));
}
}
else if (this.shape.equals("Oval")) {
if (x2 > x1 && y2 > y1) {
lstShape.add(new Oval(x1, y1, x2 - x1, y2 - y1, color));
}
else if (x2 < x1 && y2 > y1) {
lstShape.add(new Oval(x2, y1, x1 - x2, y2 - y1, color));
}
else if (x2 < x1 && y2 < y1) {
lstShape.add(new Oval(x2, y2, x1 - x2, y1 - y2, color));
}
else if (x2 > x1 && y2 < y1) {
lstShape.add(new Oval(x1, y2, x2 - x1, y1 - y2, color));
}
}
else if (this.shape.equals("TDRectangle")) {
if (x2 > x1 && y2 > y1) {
lstShape.add(new TDRectangle(x1, y1, x2 - x1, y2 - y1, color));
}
else if (x2 < x1 && y2 > y1) {
lstShape.add(new TDRectangle(x2, y1, x1 - x2, y2 - y1, color));
}
else if (x2 > x1 && y2 < y1) {
lstShape.add(new TDRectangle(x1, y2, x2 - x1, y1 - y2, color));
}
else if (x2 < x1 && y2 < y1) {
lstShape.add(new TDRectangle(x2, y2, x1 - x2, y1 - y2, color));
}
}
}
// åå§åå¾å½¢åæ
x1 = y1 = x2 = y2 = 0;
repaint();
}
public void mouseDragged(MouseEvent e) {
label.setText("æå¨é¼ æ å¨: [" + e.getX() + ", " + e.getY() + "]");
x2 = e.getX();
y2 = e.getY();
label.setText("å¾å½¢:" + shape);
repaint();
}
public void mouseMoved(MouseEvent e) {
label.setText("移å¨å¨é¼ æ å¨: [" + e.getX() + ", " + e.getY() + "]");
}
public void paint(Graphics g) {
super.paint(g);
g.setColor(this.toColor());
if (this.shape.equals("Line")) {
g.drawLine(x1, y1, x2, y2);
}
else if (this.shape.equals("Rectangle")) {
if (x2 > x1 && y2 > y1) {
g.drawRect(x1, y1, x2 - x1, y2 - y1);
}
else if (x2 < x1 && y2 > y1) {
g.drawRect(x2, y1, x1 - x2, y2 - y1);
}
else if (x2 < x1 && y2 < y1) {
g.drawRect(x2, y2, x1 - x2, y1 - y2);
}
else if (x2 > x1 && y2 < y1) {
g.drawRect(x1, y2, x2 - x1, y1 - y2);
}
}
else if (this.shape.equals("Oval")) {
if (x2 > x1 && y2 > y1) {
g.drawOval(x1, y1, x2 - x1, y2 - y1);
}
else if (x2 < x1 && y2 > y1) {
g.drawOval(x2, y1, x1 - x2, y2 - y1);
}
else if (x2 < x1 && y2 < y1) {
g.drawOval(x2, y2, x1 - x2, y1 - y2);
}
else if (x2 > x1 && y2 < y1) {
g.drawOval(x1, y2, x2 - x1, y1 - y2);
}
}
else if (this.shape.equals("TDRectangle")) {
if (x2 > x1 && y2 > y1) {
g.draw3DRect(x1, y1, x2 - x1, y2 - y1, true);
}
else if (x2 < x1 && y2 > y1) {
g.draw3DRect(x2, y1, x1 - x2, y2 - y1, true);
}
else if (x2 < x1 && y2 < y1) {
g.draw3DRect(x2, y2, x1 - x2, y1 - y2, true);
}
else if (x2 > x1 && y2 < y1) {
g.draw3DRect(x1, y2, x2 - x1, y1 - y2, true);
}
}
// ç»åºåæ¾å¨listä¸çå¾å½¢
for (Object object : lstShape) {
if (object.getClass().toString().equals("class DrawBorder$Line")) {
Line line = (Line) object;
g.setColor(line.toColor());
g.drawLine(line.x1, line.y1, line.x2, line.y2);
}
else if (object.getClass().toString()
.equals("class DrawBorder$Rectangle")) {
Rectangle rectangle = (Rectangle) object;
g.setColor(rectangle.toColor());
g.drawRect(rectangle.x1, rectangle.y1, rectangle.x2, rectangle.y2);
}
else if (object.getClass().toString().equals("class DrawBorder$Oval")) {
Oval oval = (Oval) object;
g.setColor(oval.toColor());
g.drawOval(oval.x1, oval.y1, oval.x2, oval.y2);
}
else if (object.getClass().toString().equals(
"class DrawBorder$TDRectangle")) {
TDRectangle tDRectangle = (TDRectangle) object;
g.setColor(tDRectangle.toColor());
g.draw3DRect(tDRectangle.x1, tDRectangle.y1, tDRectangle.x2,
tDRectangle.y2, false);
}
}
}
public static void main(String[] args) {
DrawBorder db = new DrawBorder();
db.display();
db.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public Color toColor() {
if (this.color.equals("Blue")) {
return Color.BLUE;
}
else if (this.color.equals("Green")) {
return Color.GREEN;
}
else if (this.color.equals("Cyan")) {
return Color.CYAN;
}
else if (this.color.equals("Gray")) {
return Color.GRAY;
}
else if (this.color.equals("Orange")) {
return Color.ORANGE;
}
else if (this.color.equals("Red")) {
return Color.RED;
}
else
return Color.BLACK;
}
class Line extends DrawBorder {
Line(int x1, int y1, int x2, int y2, String color) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.color = color;
}
}
class Rectangle extends DrawBorder {
Rectangle(int x1, int y1, int x2, int y2, String color) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.color = color;
}
}
class Oval extends DrawBorder {
Oval(int x1, int y1, int x2, int y2, String color) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.color = color;
}
}
class TDRectangle extends DrawBorder {
TDRectangle(int x1, int y1, int x2, int y2, String color) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.color = color;
}
}
}