我试图在bufferedimage上绘制水平和垂直线条.它应该看起来像一个细胞网格.但是当我运行代码时,我只看到两行:最左边的行和最上面的行(即从0,0到0的行,图像的高度和0,0到图像的宽度,0)下面是代码片段:
BufferedImage mazeImage = new BufferedImage(imgDim.width, imgDim.height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = mazeImage.createGraphics();
g2d.setBackground(Color.WHITE);
g2d.fillRect(0, 0, imgDim.width, imgDim.height);
g2d.setColor(Color.BLACK);
BasicStroke bs = new BasicStroke(2);
g2d.setStroke(bs);
// draw the black vertical and horizontal lines
for(int i=0;i<21;i++){
g2d.drawLine((imgDim.width+2)*i, 0, (imgDim.width+2)*i, imgDim.height-1);
g2d.drawLine(0, (imgDim.height+2)*i, imgDim.width-1, (imgDim.height+2)*i);
}
Run Code Online (Sandbox Code Playgroud)
和覆盖绘制方法:
public void paint(Graphics g) {
g.drawImage(mazeImage, 0, 0, this);
}
Run Code Online (Sandbox Code Playgroud)
这是一个名为RobotMaze的类,它扩展了JPanel.任何帮助表示赞赏.
我知道Java Date Time不是一个很好的前进方式,但我只是好奇发生了什么:
为什么以下行:
DateFormat df = new SimpleDateFormat("dd-MMM-yyyy", Locale.US)
不会产生任何错误,以下行:
DateFormat df = new SimpleDateFormat("DD-MMM-YYYY", Locale.US)
DateFormat df = new SimpleDateFormat("dd-mm-YYYY", Locale.US)
抛出以下异常:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'Y'
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:769)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:576)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:501)
at testing.MySchedule.main(MySchedule.java:18)
Run Code Online (Sandbox Code Playgroud)
我的意思是我只是改变案子吧?但DateFormat真的那么愚蠢还是我做错了什么?或者它与我正在使用的Locale有关?
干杯
是什么区别i = ++i;,并++i;在那里i与值的整数10?
根据我的说法i,两个表达式完成后,两者都做同样的增量工作i =11.
我想创建一个带有加号和减号的圆形按钮,并在Android Contacts应用程序中使用,如下图所示:

public ActionResult Create(FormCollection collection, FormCollection formValue)
{
try
{
Project project = new Project();
TryUpdateModel(project, _updateableFields);
var devices = collection["devices"];
string[] arr1 = ((string)devices).Split(',');
int[] arr2 = Array.ConvertAll(arr1, s => int.Parse(s));
project.User = SessionVariables.AuthenticatedUser;
var time = formValue["Date"];
project.Date = time;
project.SaveAndFlush();
foreach (int i in arr2)
{
Device d = Device.Find(i);
d.Projects.Add(project);
d.SaveAndFlush();
}
return RedirectToAction("Index");
}
catch (Exception e)
{
return View(e);
}
}
Run Code Online (Sandbox Code Playgroud)
我想将foreach包装在if语句中,检查是否
var devices = collection["devices"];
Run Code Online (Sandbox Code Playgroud)
是空的.如果它为空,则不应执行每个.对于记录,集合["devices"]是表单中复选框值的集合.
无论键是什么,我如何遍历NSMutableDictionary中的所有对象?
当我处理Java问题时,我使用集合模式.但是,在Delphi中执行它是一个噩梦,因为没有Integer对象来处理事情.
我需要一个包含数字的数据结构.我希望能够添加数字,删除数字,并检查集合的内容,每个数字必须是唯一的.
我对自己需要实现和测试bug的解决方案不感兴趣.是否有像Java的HashTable这样的现成对象?
我有一个叫做Global派生的类HttpApplication.
奇怪的是,我看到里面有很多方法Global看起来像:
void Application_Start(object sender, EventArgs e)
{
}
Run Code Online (Sandbox Code Playgroud)
代码肯定是在这个方法中执行的,所以这个方法是从某个地方调用的,但是在哪里?方法没有标记过载?
其次,我从中派生了一个类Global,让我们称之为GlobalFoo.
同样,如果我创建一个名为的方法Application_Start(),它将在我的派生类中被调用,否则Global将调用任何内容,因此我也可能从一个空类派生.
有人可以提供任何建议吗?我错过了ASP.NET的一些基本部分吗?
我有一个Java EE应用程序,我使用Hibernate.域对象,我将List/ArrayList更改为Set/HashSet,因为最好使用Sets.
但是在我的Dao实现中我遇到了一个问题:
public Set<Person> getAllPersons() {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session sess = sessionFactory.getCurrentSession();
Transaction tx = sess.beginTransaction();
@SuppressWarnings("unchecked")
Set<Item> items = (Set<Item>) sess.createQuery("from Item").list();
tx.commit();
return items;
}
Run Code Online (Sandbox Code Playgroud)
在这里我收到一个错误:
java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Set
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能避免这个错误?
提前谢谢你和最诚挚的问候.
我正在搞乱测试/练习项目,只是为了更好地理解Rails.
在我的情况下,我有三个模型:商店,用户和产品.
商店可以有三种类型:基本,中等,大型.基本最多可以有10个产品,中等50个,大100个.
我正在尝试验证这种数据,Shop的类型,并检查它在创建新产品时拥有多少产品.
到目前为止,我想出了这个代码(在shop.rb中),但它不起作用:
def lol
account = Shop.find_by_sql "SELECT account FROM shops WHERE user_id = 4 LIMIT 1"
products = Product.count_by_sql "SELECT COUNT(*) FROM products WHERE shop_id = 13"
if account = 1 && products >= 10
raise "message"
elsif account = 2 && products >= 50
raise "message"
else account = 3 && products >= 100
raise "message"
end
end
Run Code Online (Sandbox Code Playgroud)
我甚至不知道我的解决方案背后的逻辑是正确的还是什么.也许我应该验证使用
has_many
Run Code Online (Sandbox Code Playgroud)
和它的"大小"方法?我不知道.:)
java ×3
c# ×2
collections ×2
android ×1
arraylist ×1
asp.net ×1
asp.net-mvc ×1
button ×1
c ×1
c++ ×1
contacts ×1
date-format ×1
delphi ×1
drawing ×1
global-asax ×1
hibernate ×1
ios ×1
layout ×1
lines ×1
objective-c ×1
ruby ×1
set ×1
swing ×1