用java代码画粽子 java绘制

在Java中如何用程序画一个圆使用java画圆要用到绘图类Graphics,下面是实例代码和运行效果:
package com.dikea.demo01;
import java.awt.*;
import javax.swing.*;
// java绘图原理
public class demo_01extends JFrame {
MyPanel mp = null;
public static void main(String[] args) {
// TODO 自动生成的方法存根
demo_01 demo01 = new demo_01();
}
public demo_01(){
mp = new MyPanel();
this.add(mp);
this.setSize(400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
// 定义一个MyPanel面板,用于绘图区域
class MyPanel extends JPanel{
//覆盖JPanel
// Graphics 是绘图的重要类 , 可以理解成一支画笔
public void paint(Graphics g){
//1. 调用父类函数完成初始化任务
//这句话不可以少
super.paint(g);
// 先画出一个圆圈
【用java代码画粽子 java绘制】g.drawOval(100, 100, 30, 30);
}
}
代码复制进ide编程工具,运行效果如下:
求一个简单java程序代码,谢谢public class TestStar {
public static void main(String[] args) {
String star = "*";
for (int i = 0; i5; i) {
if (i == 0) {
System.out.print(" "star);
System.out.println();
}
if (i == 1) {
for (int z = 0; z4; z) {
System.out.print(" "star);
}
System.out.println();
}
if (i == 2) {
System.out.print(" ");
for (int x = 0; x3; x) {
System.out.print(" "star);
}
System.out.println();
}
if (i == 3) {
for (int y = 0; y2; y) {
System.out.print(" "star" ");
}
}
}
}
}
是好使的 但是我没找到画五角星有什么规律(五角星好象不是正规图形吧?)如果还有什么要求的话 补充问题(如果是用*填充所有的东西 不包括 “ ”的话 我可以重新再给你写一个)
MacBook Pro上利用sublime编译器编写了一段Java程序 。但是不知道怎么运行代码,原谅我问这么low逼的问题你应该安装了jdk吧 。。。安装了且配置了环境变量后就如下操作:
打开终端,切换到你的源码文件所在目录
在终端内输入javac xxx.java (这是编译命令,xxx是你的文件名)
编译后 在终端输入java xxx(xxx是你刚刚编译的文件名,这里不用.java后缀)
如何用java写这段代码?import java.security.InvalidKeyException;import java.security.NoSuchAlgorithmException;import javax.crypto.BadPaddingException;import javax.crypto.Cipher;import javax.crypto.IllegalBlockSizeException;import javax.crypto.KeyGenerator;import javax.crypto.NoSuchPaddingException;import javax.crypto.SecretKey;public class JEncrytion{
public static void main(String[] argv) {
try{KeyGenerator keygenerator = KeyGenerator.getInstance("DES");SecretKey myDesKey = keygenerator.generateKey();
Cipher desCipher;// Create the cipher
desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
// Initialize the cipher for encryption
desCipher.init(Cipher.ENCRYPT_MODE, myDesKey);//sensitive information
byte[] text = "No body can see me".getBytes();
System.out.println("Text [Byte Format] : "text);
System.out.println("Text : "new String(text));
// Encrypt the text
byte[] textEncrypted = desCipher.doFinal(text);
System.out.println("Text Encryted : "textEncrypted);
// Initialize the same cipher for decryption
desCipher.init(Cipher.DECRYPT_MODE, myDesKey);// Decrypt the text
byte[] textDecrypted = desCipher.doFinal(textEncrypted);
System.out.println("Text Decryted : "new String(textDecrypted));
}catch(NoSuchAlgorithmException e){
e.printStackTrace();
}catch(NoSuchPaddingException e){
e.printStackTrace();
}catch(InvalidKeyException e){
e.printStackTrace();
}catch(IllegalBlockSizeException e){
e.printStackTrace();
}catch(BadPaddingException e){
e.printStackTrace();
}
}
}
用java 在窗体中画一个简单图形 。帮你改了一下 。
你要画在panel上,然后frame.add(panel)就能显示 。
是不是和applet搞混了,applet复写一些方法就能显示,但现在你编的是java gui
import java.awt.*;
import java.awt.Event.*;
import javax.swing.*; //import javax.swing.Timer;
import java.awt.BasicStroke;
//import java.util.Date;
//import java.text.*;
//import java.util.*;
public class TestGui {
public void paint(Graphics g) {
Graphics2D a2d = (Graphics2D) g;
int x = 120, y = 90, width = 150, height = 150;
a2d.setColor(Color.red);
a2d.setStroke(new BasicStroke(3.0f)); // 设置线条宽度 , 3.0即线的宽度
a2d.drawOval(x, y, width, height);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
// frame.add(new paint(),BorderLayout.CENTER);
frame.setSize(500, 500);
frame.setLocation(200, 200);
frame.setVisible(true);
Panel p = new Panel();
frame.add(p);
// frame.paint(null);
// TODO code application logic here
}
}
class Panel extends JPanel {
// 重新覆盖paint方法
public void paint(Graphics g) {
super.paint(g);
Graphics2D a2d = (Graphics2D) g;
int x = 120, y = 90, width = 150, height = 150;
a2d.setColor(Color.red);
a2d.setStroke(new BasicStroke(3.0f)); // 设置线条宽度,3.0即线的宽度
a2d.drawOval(x, y, width, height);
}
}
求助大神如何用Java写出这两个题目的代码?第一题
package baidu;
public class Student {
protected String name;
protected int age;
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public void show(){
System.out.println("name = "name);
System.out.println("age = "age);
}
}
---------------------------------
package baidu;
public class Undergraduate extends Student {
private String degree;
public Undergraduate(String name, int age, String degree) {
super(name, age);
this.degree = degree;
}
public void show(){
System.out.println("name = "name);
System.out.println("age = "age);
System.out.println("degree = "degree);
}
}
------------------------
package baidu;
public class TestRun {
public static void main(String[] args) {
Student s = new Student("singi",12);
s.show();
Undergraduate ug = new Undergraduate("lily",23,"本科");
ug.show();
}
}
输出:
name = singi
age = 12
name = lily
age = 23
degree = 本科
第二题:
package baidu;
public class Man {
String name;
public Man(String name) {
this.name = name;
}
public void business(){
System.out.println("在方法内输出谈生意");
}
}
----------------
package baidu;
public class SuperMan extends Man {
String name;
public SuperMan(String name, String name1) {
super(name);
this.name = name1;
}
@Override
public void business() {
System.out.println("在方法内输出谈几个亿用java代码画粽子的大单子");
}
public void fly(){
System.out.println("在方法内输出超人不会飞");
}
}
------------------
package baidu;
public class TestMan {
public static void main(String[] args) {
Man m = new Man("singi");
System.out.println(m.name);
m.business();
SuperMan sm = new SuperMan("lily","xiaoming");
System.out.println(sm.name);
sm.business();
sm.fly();
}
}
输出:
singi
在方法内输出谈生意
xiaoming
在方法内输出谈几个亿用java代码画粽子的大单子
在方法内输出超人不会飞
关于用java代码画粽子和java绘制的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读