本文介绍了如何在java AWT中滚动形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码将我的8个形状放在8个不同的位置。



The below code places my 8 shapes in 8 distinct positions.

Shape aShape = new RoundRectangle2D.Double(60,112,310,60,10,10);
Shape bShape = new RoundRectangle2D.Double(60,194,310,60,10,10);
Shape cShape = new RoundRectangle2D.Double(60,276,310,60,10,10);
Shape dShape = new RoundRectangle2D.Double(60,358,310,60,10,10);
Shape eShape = new RoundRectangle2D.Double(60,440,310,60,10,10);
Shape fShape = new RoundRectangle2D.Double(60,522,310,60,10,10);
Shape gShape = new RoundRectangle2D.Double(60,604,310,60,10,10);
Shape hShape = new RoundRectangle2D.Double(60,686,310,60,10,10);





我已经硬编码了字体也在形状中。





I have hardcoded the position of Font also in the shape.

//		aShape border color
		graphics2D.setStroke(new BasicStroke(borderThickness));
		graphics2D.setColor(Color.WHITE);

//		Drawing a Rounded Rectangle for A
		graphics2D.draw(aShape);
		graphics2D.setStroke(oldStroke);

//		Setting the Background Color
		graphics2D.setColor(color);
		graphics2D.fill(aShape);

//		Setting the font inside the shape
		Font aFont = new Font("Serif", Font.PLAIN,25);
		graphics2D.setFont(aFont);
		graphics2D.setColor(Color.WHITE);
		graphics2D.drawString(ProjectConstants.A_KEY, 80,148);







但现在我想要一次只显示4个并引入滚动。由于X和Y位置是硬编码的,我对如何滚动我的形状一无所知?



有人可以分享一些关于如何动态加载我的图形形状的见解滚动时把它放在合适的位置?



我尝试过的事情:



我试图在一个面板中放置4个形状,在另一个面板中放置另外4个形状,并尝试引入滚动,但这将在一个滚动中替换4个形状。




But now I want to show only 4 at a time and introduce scrolling. Since the X and Y positions are hardcoded I am clueless as to how will I scroll my shapes ?

Can someone share some insights on how to dynamically load my graphical shapes and place it in a proper position when Scrolled ?

What I have tried:

I tried to put 4 shapes in one panel and another 4 shapes in another panel, and tried to introduce Scrolling, but that would replace 4 shapes in one scroll.

推荐答案


这篇关于如何在java AWT中滚动形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 01:04