Javaグラフィックサンプル(Swing版):テクスチャーパターン

Javaグラフィックサンプル(Swing版):図形内へのテクスチャーパターンの貼り付け方やいろいろなテクスチャーパターンのサンプルを掲載しています。
- Page 13 - << 先頭のページ< 前のページ次のページ >最後のページ >>

Home > サンプル集 > Swingサンプル集 > いろいろなテクスチャーパターン -Swing版-


いろいろなテクスチャーパターン -Swing版-

このページには、以下のサンプルを掲載しています。 下の項目をクリックをすると各サンプルにジャンプします。 ※2週間以内の新着記事はNewアイコン、更新記事はUpアイコンが表示されます。
  1. テクスチャーパターン(市松模様) ( TextureSample01.java )  
  2. テクスチャーパターン(格子模様) ( TextureSample02.java )<  
  3. テクスチャーパターン(ドットパターン) ( TextureSample03.java )  
  4. テクスチャーパターン(斜めの格子模様) ( TextureSample04.java )  
  5. テクスチャーパターン(斜めの格子模様)  
  6. テクスチャーパターン(十字模様) ( TextureSample06.java )  
  7. テクスチャーパターン(文字列) ( TextureSample07.java )  

■テクスチャーパターン(市松模様)

[ サンプルプログラムのソースコード - TextureSample01.java - ]
  1. import javax.swing.JFrame;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Rectangle;
  6. import java.awt.TexturePaint;
  7. import java.awt.image.BufferedImage;
  8. public class TextureSample01 extends JFrame {
  9.   private static final long serialVersionUID = 1L;
  10.   public TextureSample01() {
  11.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  12.   }
  13.   public void paint(Graphics g){
  14.     Graphics2D g2 = (Graphics2D)g;
  15.     g2.clearRect(0, 0, getWidth(), getHeight());
  16.     BufferedImage bi = new BufferedImage(20,20,BufferedImage.TYPE_INT_RGB);
  17.     Graphics2D bg = bi.createGraphics();
  18.     Rectangle r = new Rectangle(0,0,20,20);
  19.     bg.setColor(Color.ORANGE);
  20.     bg.fillRect(0, 0, 10, 10);
  21.     bg.fillRect(10, 10, 10, 10);
  22.     bg.setColor(Color.GREEN);
  23.     bg.fillRect(10, 0, 10, 10);
  24.     bg.fillRect(0, 10, 10, 10);
  25.     TexturePaint tp = new TexturePaint(bi,r);
  26.     g2.setPaint(tp);
  27.     g2.fillOval(50, 60, 100, 100);
  28.   }
  29.   public static void main(String[] args) {
  30.     JFrame f = new TextureSample01();
  31.     f.setTitle("Swingサンプル(市松模様のテクスチャーパターン)");
  32.     f.setSize(200,200);
  33.     f.setBackground(Color.WHITE);
  34.     f.setVisible(true);
  35.   }
  36. }
[ サンプルプログラムの実行結果 ]

[ 関連ページ ]
テクスチャーパターン(市松模様)のアプレット版サンプル




■テクスチャーパターン(格子模様)

[ サンプルプログラムのソースコード - TextureSample02.java - ]
  1. import javax.swing.JFrame;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Rectangle;
  6. import java.awt.TexturePaint;
  7. import java.awt.image.BufferedImage;
  8. public class TextureSample02 extends JFrame {
  9.   private static final long serialVersionUID = 1L;
  10.   public TextureSample02() {
  11.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  12.   }
  13.   public void paint(Graphics g){
  14.     Graphics2D g2 = (Graphics2D)g;
  15.     g2.clearRect(0, 0, getWidth(), getHeight());
  16.     BufferedImage bi = new BufferedImage(10,10,BufferedImage.TYPE_INT_RGB);
  17.     Graphics2D bg = bi.createGraphics();
  18.     Rectangle r = new Rectangle(0,0,10,10);
  19.     bg.setColor(Color.CYAN);
  20.     bg.fillRect(0, 0, 10, 10);
  21.     bg.setColor(Color.BLUE);
  22.     bg.drawLine(0, 5, 10, 5);
  23.     bg.drawLine(5, 0, 5, 10);
  24.     TexturePaint tp = new TexturePaint(bi,r);
  25.     g2.setPaint(tp);
  26.     g2.fillOval(50, 60, 100, 100);
  27.   }
  28.   public static void main(String[] args) {
  29.     JFrame f = new TextureSample02();
  30.     f.setTitle("Swingサンプル(格子模様のテクスチャーパターン)");
  31.     f.setSize(200,200);
  32.     f.setBackground(Color.WHITE);
  33.     f.setVisible(true);
  34.   }
  35. }
[ サンプルプログラムの実行結果 ]

[ 関連ページ ]
テクスチャーパターン(格子模様)のアプレット版サンプル




■テクスチャーパターン(ドットパターン)

[ サンプルプログラムのソースコード - TextureSample03.java - ]
  1. import javax.swing.JFrame;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Rectangle;
  6. import java.awt.TexturePaint;
  7. import java.awt.image.BufferedImage;
  8. public class TextureSample03 extends JFrame {
  9.   private static final long serialVersionUID = 1L;
  10.   public TextureSample03() {
  11.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  12.   }
  13.   public void paint(Graphics g){
  14.     Graphics2D g2 = (Graphics2D)g;
  15.     g2.clearRect(0, 0, getWidth(), getHeight());
  16.     BufferedImage bi = new BufferedImage(10,10,BufferedImage.TYPE_INT_RGB);
  17.     Graphics2D bg = bi.createGraphics();
  18.     Rectangle r = new Rectangle(0,0,10,10);
  19.     bg.setColor(Color.ORANGE);
  20.     bg.fillRect(0, 0, 10, 10);
  21.     bg.setColor(Color.BLUE);
  22.     bg.fillRect(2, 2, 2, 2);
  23.     bg.fillRect(7, 2, 2, 2);
  24.     bg.fillRect(2, 7, 2, 2);
  25.     bg.fillRect(7, 7, 2, 2);
  26.     TexturePaint tp = new TexturePaint(bi,r);
  27.     g2.setPaint(tp);
  28.     g2.fillOval(50, 60, 100, 100);
  29.   }
  30.   public static void main(String[] args) {
  31.     JFrame f = new TextureSample03();
  32.     f.setTitle("Swingサンプル(ドットパターンのテクスチャーパターン)");
  33.     f.setSize(200,200);
  34.     f.setBackground(Color.WHITE);
  35.     f.setVisible(true);
  36.   }
  37. }
[ サンプルプログラムの実行結果 ]

[ 関連ページ ]
テクスチャーパターン(ドットパターン)のアプレット版サンプル




■テクスチャーパターン(斜めの格子模様)

[ サンプルプログラムのソースコード - TextureSample04.java - ]
  1. import javax.swing.JFrame;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Rectangle;
  6. import java.awt.TexturePaint;
  7. import java.awt.image.BufferedImage;
  8. public class TextureSample04 extends JFrame {
  9.   private static final long serialVersionUID = 1L;
  10.   public TextureSample04() {
  11.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  12.   }
  13.   public void paint(Graphics g){
  14.     Graphics2D g2 = (Graphics2D)g;
  15.     g2.clearRect(0, 0, getWidth(), getHeight());
  16.     BufferedImage bi = new BufferedImage(10,10,BufferedImage.TYPE_INT_RGB);
  17.     Graphics2D bg = bi.createGraphics();
  18.     Rectangle r = new Rectangle(0,0,10,10);
  19.     bg.setColor(Color.ORANGE);
  20.     bg.fillRect(0, 0, 10, 10);
  21.     bg.setColor(Color.BLUE);
  22.     bg.drawLine(0, 0, 10, 10);
  23.     bg.drawLine(10, 0, 0, 10);
  24.     TexturePaint tp = new TexturePaint(bi,r);
  25.     g2.setPaint(tp);
  26.     g2.fillOval(50, 60, 100, 100);
  27.   }
  28.   public static void main(String[] args) {
  29.     JFrame f = new TextureSample04();
  30.     f.setTitle("Swingサンプル(斜めの格子模様のテクスチャーパターン)");
  31.     f.setSize(200,200);
  32.     f.setBackground(Color.WHITE);
  33.     f.setVisible(true);
  34.   }
  35. }
[ サンプルプログラムの実行結果 ]

[ 関連ページ ]
テクスチャーパターン(斜めの格子模様)のアプレット版サンプル




■テクスチャーパターン(十字模様)

[ サンプルプログラムのソースコード - TextureSample05.java - ]
  1. import javax.swing.JFrame;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Rectangle;
  6. import java.awt.TexturePaint;
  7. import java.awt.image.BufferedImage;
  8. public class TextureSample05 extends JFrame {
  9.   private static final long serialVersionUID = 1L;
  10.   public TextureSample05() {
  11.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  12.   }
  13.   public void paint(Graphics g){
  14.     Graphics2D g2 = (Graphics2D)g;
  15.     g2.clearRect(0, 0, getWidth(), getHeight());
  16.     BufferedImage bi = new BufferedImage(10,10,BufferedImage.TYPE_INT_RGB);
  17.     Graphics2D bg = bi.createGraphics();
  18.     Rectangle r = new Rectangle(0,0,10,10);
  19.     bg.setColor(Color.ORANGE);
  20.     bg.fillRect(0, 0, 10, 10);
  21.     bg.setColor(Color.BLUE);
  22.     bg.drawLine(5, 3, 5, 7);
  23.     bg.drawLine(3, 5, 7, 5);
  24.     TexturePaint tp = new TexturePaint(bi,r);
  25.     g2.setPaint(tp);
  26.     g2.fillOval(50, 60, 100, 100);
  27.   }
  28.   public static void main(String[] args) {
  29.     JFrame f = new TextureSample05();
  30.     f.setTitle("Swingサンプル(十字模様のテクスチャーパターン)");
  31.     f.setSize(200,200);
  32.     f.setBackground(Color.WHITE);
  33.     f.setVisible(true);
  34.   }
  35. }
[ サンプルプログラムの実行結果 ]

[ 関連ページ ]
テクスチャーパターン(十字模様)のアプレット版サンプル




■テクスチャーパターン(ハート模様)

[ サンプルプログラムのソースコード - TextureSample06.java - ]
  1. import javax.swing.JFrame;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.RadialGradientPaint;
  6. import java.awt.Rectangle;
  7. import java.awt.TexturePaint;
  8. import java.awt.geom.Arc2D;
  9. import java.awt.geom.Area;
  10. import java.awt.geom.Ellipse2D;
  11. import java.awt.image.BufferedImage;
  12. public class TextureSample06 extends JFrame {
  13.   private static final long serialVersionUID = 1L;
  14.   public TextureSample06() {
  15.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  16.   }
  17.   public void paint(Graphics g){
  18.     Graphics2D g2 = (Graphics2D)g;
  19.     g2.clearRect(0, 0, getWidth(), getHeight());
  20.     BufferedImage bi = new BufferedImage(30,30,BufferedImage.TYPE_INT_RGB);
  21.     Graphics2D bg = bi.createGraphics();
  22.     Rectangle r = new Rectangle(0,0,30,30);
  23.     Ellipse2D e1 = new Ellipse2D.Double( 0, 0, 10, 10);
  24.     Ellipse2D e2 = new Ellipse2D.Double(10, 0, 10, 10);
  25.     Arc2D arc = new Arc2D.Double(0, 4, 20, 25,34,112,Arc2D.PIE);
  26.     Area a1 = new Area(e1);
  27.     Area a2 = new Area(e2);
  28.     Area a3 = new Area(arc);
  29.     a1.add(a2);
  30.     a1.add(a3);
  31.     bg.setColor(Color.cyan);
  32.     bg.fillRect(0, 0, 50, 50);
  33.     float[] dist = {0.0f, 0.5f, 1.0f};
  34.     Color[] colors = {Color.WHITE, Color.PINK, Color.MAGENTA};
  35.     RadialGradientPaint rgp =
  36.         new RadialGradientPaint( 10, 20, 30, dist, colors);
  37.     bg.setPaint(rgp);
  38.     bg.fill(a1);
  39.     bg.setColor(Color.MAGENTA);
  40.     bg.draw(a1);
  41.     TexturePaint tp = new TexturePaint(bi,r);
  42.     g2.setPaint(tp);
  43.     g2.fillOval(50, 60, 100, 100);
  44.     g2.setColor(Color.BLUE);
  45.     g2.drawOval(50, 60, 100, 100);
  46.   }
  47.   public static void main(String[] args) {
  48.     JFrame f = new TextureSample06();
  49.     f.setTitle("Swingサンプル(ハート模様のテクスチャーパターン)");
  50.     f.setSize(200,200);
  51.     f.setBackground(Color.WHITE);
  52.     f.setVisible(true);
  53.   }
  54. }
[ サンプルプログラムの実行結果 ]

[ 関連ページ ]
テクスチャーパターン(ハート模様)のアプレット版サンプル




■テクスチャーパターン(文字列)

[ サンプルプログラムのソースコード - TextureSample07.java - ]
  1. import javax.swing.JFrame;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Rectangle;
  6. import java.awt.TexturePaint;
  7. import java.awt.font.TextAttribute;
  8. import java.awt.geom.Ellipse2D;
  9. import java.awt.image.BufferedImage;
  10. import java.text.AttributedCharacterIterator;
  11. import java.text.AttributedString;
  12. public class TextureSample07 extends JFrame {
  13.   private static final long serialVersionUID = 1L;
  14.   public TextureSample07() {
  15.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  16.   }
  17.   public void paint(Graphics g){
  18.     Graphics2D g2 = (Graphics2D)g;
  19.     g2.clearRect(0, 0, getWidth(), getHeight());
  20.     BufferedImage bi = new BufferedImage(35,40,BufferedImage.TYPE_INT_RGB);
  21.     Graphics2D bg = bi.createGraphics();
  22.     bg.setBackground(Color.BLUE);
  23.     bg.clearRect(0, 0, bi.getWidth(), bi.getHeight());
  24.     Rectangle r = new Rectangle(0,0,35,40);
  25.     AttributedString as = new AttributedString("Java");
  26.     as.addAttribute(TextAttribute.WEIGHT, 8);
  27.     as.addAttribute(TextAttribute.SIZE, 16, 0, 1);
  28.     as.addAttribute(TextAttribute.FOREGROUND, Color.ORANGE,0,1);
  29.     as.addAttribute(TextAttribute.FOREGROUND, Color.GREEN,1,4);
  30.     AttributedCharacterIterator aci = as.getIterator();
  31.     bg.drawString(aci,2, 18);
  32.     bg.drawString(aci,20, 38);
  33.     bg.drawString(aci,-14, 38);
  34.     TexturePaint tp = new TexturePaint(bi,r);
  35.     g2.setPaint(tp);
  36.     Ellipse2D ellipse = new Ellipse2D.Double();
  37.     ellipse.setFrame(50,60,100,100);
  38.     g2.fill(ellipse);
  39.   }
  40.   public static void main(String[] args) {
  41.     JFrame f = new TextureSample07();
  42.     f.setTitle("Swingサンプル(文字列のテクスチャーパターン)");
  43.     f.setSize(200,200);
  44.     f.setBackground(Color.WHITE);
  45.     f.setVisible(true);
  46.   }
  47. }
[ サンプルプログラムの実行結果 ]

[ 関連ページ ]
テクスチャーパターン(文字列)のアプレット版サンプル




- Page 13 - << 先頭のページ< 前のページ次のページ >最後のページ >>


最終更新日:2019/02/13

2015-03-01からの訪問者数
  1014 人